Created
September 5, 2022 17:48
-
-
Save aleksandarzekovic/5ffb226fe9836854347eff80a19e5636 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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