fun complete(): X {
TODO("your implementation")
}
suspend fun suspendComplete(): X {
return suspendCoroutine { continuation ->
val result = runCatching { complete() }
continuation.resumeWith(result)
}
}
🚫 7
l
louiscad
08/14/2019, 7:50 PM
suspendCancellableCoroutine
and its non cancellable counterpart are for callbacks which is not the case here. If your code is blocking, you'll want to use
withContext
and pass
Dispatchers.Default
for CPU bound operations, and
<http://Dispatchers.IO|Dispatchers.IO>
for blocking input/output. You should probably read the docs to see what's possible with kotlinx.coroutines.
louiscad
08/14/2019, 7:51 PM
If you want, I can also link one or more video talks that cover it.
m
molikuner
08/14/2019, 8:35 PM
Actually I found that code in a library and wasn't sure, so I asked. Now I'll comment there and probably link to this thread.
So thank you for confirming my initial thought.