I have a blocking call that I'm able to cancel. Wi...
# coroutines
I have a blocking call that I'm able to cancel. Will
be enough or should I wrap it in
? I'm not completely sure how
works here.
I think whether to launch a coroutine is a separate issue and doesn’t affect cancellation. If you don’t launch a separate coroutine to run the blocking call, then the caller will never “see” the suspension – it will just look like the call never suspended, since the calling thread will be blocked. However, if the calling coroutine’s
is cancelled, then your blocking call would still get cancelled immediately. If you’re wrapping your blocking call in a suspend function, I would expect the function to launch a separate coroutine to actually block so it doesn’t block the caller, but that’s not a cancellation-related concern. In other words, I believe that if you register an
action, that action will be executed synchronously on the thread that invoked
, and so even if the thread that called
is blocked the cancellation will still occur.
👍🏼 1