Last active
April 21, 2020 10:25
-
-
Save PatilShreyas/cface010611ce7711bc62350e27b85db to your computer and use it in GitHub Desktop.
This file contains 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
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