Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fun getAllPosts() = flow<State<List<Post>>> {
// Emit loading state
emit(State.loading())
val snapshot = mPostsCollection.get().await()
val posts = snapshot.toObjects(Post::class.java)
// Emit success state with data
emit(State.success(posts))
}.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