Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Last active April 21, 2020 10:25
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 PatilShreyas/cface010611ce7711bc62350e27b85db to your computer and use it in GitHub Desktop.
Save PatilShreyas/cface010611ce7711bc62350e27b85db to your computer and use it in GitHub Desktop.
fun addPost(post: Post) = flow<State<DocumentReference>> {
// Emit loading state
emit(State.loading())
val postRef = mPostsCollection.add(post).await()
// Emit success state with post reference
emit(State.success(postRef))
}.catch {
// If exception is thrown, emit failed state along with message.
emit(State.failed(it.message.toString()))
}.flowOn(Dispatchers.IO)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment