Commit 65130ce7 authored by Mygod's avatar Mygod

Defer launching daemon threads to improve start-up speed

parent dac2cc4f
...@@ -107,15 +107,14 @@ class GuardedProcessPool(private val onFatal: suspend (IOException) -> Unit) : C ...@@ -107,15 +107,14 @@ class GuardedProcessPool(private val onFatal: suspend (IOException) -> Unit) : C
private val job = Job() private val job = Job()
override val coroutineContext get() = Dispatchers.Main + job override val coroutineContext get() = Dispatchers.Main + job
private val guards = ArrayList<Guard>()
@MainThread @MainThread
fun start(cmd: List<String>, onRestartCallback: (suspend () -> Unit)? = null) { fun start(cmd: List<String>, onRestartCallback: (suspend () -> Unit)? = null) {
Crashlytics.log(Log.DEBUG, TAG, "start process: " + Commandline.toString(cmd)) Crashlytics.log(Log.DEBUG, TAG, "start process: " + Commandline.toString(cmd))
val guard = Guard(cmd) Guard(cmd).apply {
guard.start() start() // if start fails, IOException will be thrown directly
guards += guard launch { looper(onRestartCallback) }
launch(start = CoroutineStart.UNDISPATCHED) { guard.looper(onRestartCallback) } }
} }
@MainThread @MainThread
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment