Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
suspend fun someTaskWrapped() = suspendCancellableCoroutine<Int> {
it.invokeOnCancellation {
// Cancel any task or handle resources that you want
}
someTask(
object:Callback{
override fun onSuccess(result: Int) {
it.resume(result)
// Resume the calling coroutine with this result
}
override fun onFailure(e: Exception) {
it.resumeWithException(e)
// Resume the calling coroutine with an exception
// And let it handle the failure correctly
}
}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment