Thiyagu
12/27/2019, 6:58 PMoctylFractal
12/27/2019, 6:59 PMisActive
or yield
) in onEach
, cancelling the context should sufficelaunchIn
also returns the Job
that it starts, so if you hold on to that you can cancel it toobdawg.io
12/27/2019, 7:02 PMInfiniteFlowProcessor
class InfiniteFlowProcessor : CoroutineScope {
private val job = Job()
override val coroutineContext get() = job + Executors...asCoroutineDispatcher()
fun start() {
...launchIn(this)
}
fun stop() {
job.cancelChildren()
}
}
private val scope = CoroutineScope(job + Executors...asCoroutineDispatcher())
fun start() {
...launchIn(scope)
}
Thiyagu
12/27/2019, 7:16 PMchannelFlow
block also will be cancelled.
fun stop () {
scope.cancel()
}
bdawg.io
12/27/2019, 7:20 PM.cancel
vs .cancelChildren
is you won't be able to have start()
do anything after stop()
has been called because the val job
has been cancelled fully, vs just its children jobs