kevinherron
12/09/2020, 12:44 PMsuspendCancellableCoroutine
instead of suspendCoroutine
when there is no way to propagate cancellation to the adapted API and no action to run via CancellableContinuation::invokeOnCancellation
?gildor
12/09/2020, 2:21 PMbezrukov
12/09/2020, 7:48 PMsuspendCoroutine
makes your code non-cooperative to cancellation (even assuming you can't propagate cancellation to adapted API). Also adapter API must eventually completes (either successfully or exceptionally), otherwise caller scope will never transits to terminal state (it may lead to leaking resources that supposed to be closed via job.invokeOnCompletion
).bezrukov
12/09/2020, 7:58 PMsuspendCoroutine
2. If you want this fun to behave like "it's support cancellation" - use suspendCancellableCoroutine
3. If you don't trust the API too much, or if you know that it may never complete - use suspendCancellableCoroutine
4. otherwise you can use suspendCoroutine