Asad Mehmood
11/23/2022, 9:57 AMnative suspend fun
) in rust via JNI. I've managed to create a function which starts an async rust fn in another thread and immediately returns COROUTINE_SUSPENDED
to kotlin.
The question is: Does resumeWith
run in the native thread (Does is treat the native thread as a dispatcher) or dispatch back to the kotlin dispatcher? I'm using a single thread to call resumeWith as setting up and tearing down JNI Threads are expensive and I would like to know whether its cheap or if it could end up starving other calls to resumeWith? Should I be using a dynamic blocking threadpool to call resumeWith?
See for rust code example: https://github.com/mehmooda/suspendlib/blob/main/src/lib.rsSam
11/23/2022, 11:00 AMresumeWith
.Sam
11/23/2022, 11:02 AMSam
11/23/2022, 11:10 AMDispatchers.UNCONFINED
), that’s their problem, not yours 😄Asad Mehmood
11/23/2022, 11:39 AMSam
11/23/2022, 11:44 AMresumeWith
method is a no-op if the continuation was already cancelled. (It’s an error if the continuation already resumed, though). Docs: https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-cancellable-continuation/