Created
September 8, 2020 21:09
-
-
Save NikolaDespotoski/e2a033ac88c1d2fcae5e7b5d96a5ccbd to your computer and use it in GitHub Desktop.
Await Google Play Services Task in coroutine
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 <TResult> Task<TResult>.awaitTask() = | |
suspendCancellableCoroutine<Task<TResult>> { continuation -> | |
addOnCompleteListener { | |
continuation.resume(it) | |
} | |
} | |
suspend fun <TResult> Task<TResult>.awaitTaskResult() = | |
suspendCancellableCoroutine<TResult> { continuation -> | |
addOnCanceledListener { | |
continuation.cancel() | |
} | |
addOnSuccessListener { | |
continuation.resume(it) | |
} | |
addOnFailureListener { continuation.resumeWithException(it) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment