Created
January 30, 2021 17:46
-
-
Save GauravChaddha1996/fce016f692a6c54084503289d457eab1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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