Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ import com.v2ray.ang.util.PluginUtil
import com.v2ray.ang.util.Utils
import go.Seq
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.launch
import libv2ray.Libv2ray
import java.util.concurrent.Executors

class V2RayTestService : Service() {
private val realTestScope by lazy { CoroutineScope(Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()).asCoroutineDispatcher()) }
private val realTestScope by lazy { CoroutineScope(SupervisorJob() + Dispatchers.IO) }

/**
* Initializes the V2Ray environment.
Expand Down Expand Up @@ -59,6 +60,14 @@ class V2RayTestService : Service() {
return super.onStartCommand(intent, flags, startId)
}

/**
* Cleans up coroutines
*/
override fun onDestroy() {
super.onDestroy()
realTestScope.cancel() // Cancel the entire scope and its children
}

/**
* Binds the service.
* @param intent The intent.
Expand Down