Dico
05/04/2019, 5:58 PMfun CoroutineScope.xxxAsync()
for functions that launch something and return immediately, and suspend fun xxx()
for functions that suspend/block until all of their execution completes.
Much of the kotlinx.coroutines API uses lambdas that are suspend and have a CoroutineScope
receiver. The CoroutineScope
allows developers to write coroutines with cancellability in mind - by checking isActive
. What's the best way to get access to this in a suspend fun
?coroutineContext[Job]!!.isActive
, but this is more ugly. Maybe use coroutineScope { }
if it's needed?louiscad
05/04/2019, 6:07 PMcoroutineScope
. For your use case though, maybe all you need is coroutineContext.ensureActive()
so it throws the CancellationException
in tight loops?Dico
05/05/2019, 2:13 PMlouiscad
05/05/2019, 3:15 PM