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
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