Skip to content

Instantly share code, notes, and snippets.

@TorkelV
Created February 24, 2021 12:09
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 TorkelV/8647bf105b529da5e50cc3890db8c8f2 to your computer and use it in GitHub Desktop.
Save TorkelV/8647bf105b529da5e50cc3890db8c8f2 to your computer and use it in GitHub Desktop.
fun Query.asFlow(): Flow<QuerySnapshot> {
return callbackFlow {
val callback = addSnapshotListener { querySnapshot, ex ->
if (ex != null) {
close(ex)
} else {
offer(querySnapshot!!)
}
}
awaitClose {
callback.remove()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment