Does this make any sense, or has any benefit? ```...
# coroutines
m
Does this make any sense, or has any benefit?
Copy code
fun complete(): X {
    TODO("your implementation")
}
suspend fun suspendComplete(): X {
    return suspendCoroutine { continuation  ->
        val result = runCatching { complete() }
        continuation.resumeWith(result)
    }
}
🚫 7
l
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.
If you want, I can also link one or more video talks that cover it.
m
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.
👍 1
l
Yes, please link that library so I can avoid it 😁