louiscad
10/22/2018, 12:41 PMcoroutineScope {
val daemonLikeJob = launch { while (true) /* Do sth until everything is done */ }
coroutineScope {
launch { /* do work */ }
launch { /* do work */ }
}
daemonLikeJob.cancel()
}
robin
10/22/2018, 12:44 PMlaunchDaemon
or a way to tell launch via its context
parameter that I want daemon-like behavior, without having to know any of the surrounding code and the current coroutine scope. I'd write that function myself but not sure how right now.louiscad
10/22/2018, 1:03 PMrobin
10/22/2018, 2:30 PMlouiscad
10/22/2018, 2:43 PMrobin
10/22/2018, 3:10 PMlouiscad
10/22/2018, 3:14 PMval scopeJob = coroutineContext[Job]!!
), launch the daemon from GlobalScope
or another global but custom scope, and call scopeJob.invokeOnCompletion { daemonJob.cancel() }
robin
10/22/2018, 3:16 PM