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