--

There is another limitation you didn't mention: sometimes you just want to silently cancel a coroutine manually from the coroutine itself by throwing a CancellationException explicitly. In that case, ensureActive won't throw but you still want to rethrow the exception manually.

But I guess for that case, you recommend calling coroutineContext.cancel() instead of throwing a CancellationException manually ?

--

--

Christophe Beyls
Christophe Beyls

Written by Christophe Beyls

Android developer from Belgium, blogging about advanced programming topics.

Responses (1)