Skip to content

Instantly share code, notes, and snippets.

@DawnImpulse
Created February 28, 2020 05:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DawnImpulse/e7bad7271388935f9a2f551fdc0c619c to your computer and use it in GitHub Desktop.
Save DawnImpulse/e7bad7271388935f9a2f551fdc0c619c to your computer and use it in GitHub Desktop.
suspending kotlin coroutine
suspend fun setValue(ref: DatabaseReference, value: Any) = suspendCoroutine<Boolean> { continuation ->
ref.setValue(value)
.addOnSuccessListener {
continuation.resume(true)
}
.addOnFailureListener {
continuation.resumeWithException(it)
}
}
// usage
GlobalScope.launch {
val def = async{setValue(ref,val)}
println(def.await());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment