Skip to content

Instantly share code, notes, and snippets.

@chenzhang2006
Last active April 1, 2022 17:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chenzhang2006/f6dc04a70985735a732c2b7031d67210 to your computer and use it in GitHub Desktop.
Save chenzhang2006/f6dc04a70985735a732c2b7031d67210 to your computer and use it in GitHub Desktop.
Example 1 Helper
internal suspend inline fun <T> getResult(block: () -> T): Result<T> = try {
block().let { Result.success(it) }
} catch (e: Exception) {
// Ensure coroutine cancellation can propagate to parent coroutine
if (e is CancellationException) throw e
// TODO Log with diagnostic information
Result.failure(e)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment