Skip to content

Instantly share code, notes, and snippets.

@PatilShreyas
Created April 24, 2020 04:45
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/ab2f55d46b123e10e048daf07e15e431 to your computer and use it in GitHub Desktop.
Save PatilShreyas/ab2f55d46b123e10e048daf07e15e431 to your computer and use it in GitHub Desktop.
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