Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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