Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aleksandarzekovic/5ffb226fe9836854347eff80a19e5636 to your computer and use it in GitHub Desktop.
Save aleksandarzekovic/5ffb226fe9836854347eff80a19e5636 to your computer and use it in GitHub Desktop.
inline fun resumeCancellableWith(
result: Result<T>,
noinline onCancellation: ((cause: Throwable) -> Unit)?
) {
val state = result.toState(onCancellation)
if (dispatcher.isDispatchNeeded(context)) {
_state = state
resumeMode = MODE_CANCELLABLE
dispatcher.dispatch(context, this)
} else {
executeUnconfined(state, MODE_CANCELLABLE) {
if (!resumeCancelled(state)) {
resumeUndispatchedWith(result)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment