Skip to content

Instantly share code, notes, and snippets.

@hiranya911
Created December 25, 2018 21:24
Show Gist options
  • Save hiranya911/50e65e2cc3ea010a5a4b98321195c8b3 to your computer and use it in GitHub Desktop.
Save hiranya911/50e65e2cc3ea010a5a4b98321195c8b3 to your computer and use it in GitHub Desktop.
import com.google.android.gms.tasks.Task
import kotlinx.coroutines.experimental.suspendCancellableCoroutine
suspend fun <T> Task<T>.await() =
suspendCancellableCoroutine<T> {
this.addOnSuccessListener(it::resume)
this.addOnFailureListener(it::resumeWithException)
this.addOnCanceledListener { it.cancel() }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment