Last active
June 10, 2020 08:21
-
-
Save raulh82vlc/b860c2ea8ba67c4c220098a0b7adba6b to your computer and use it in GitHub Desktop.
flow builder and transforming into an Observable
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
@ExperimentalCoroutinesApi | |
override fun search(token: String, query: String) | |
: Observable<Either<Throwable, List<TweetApiModel>>> | |
= flow<Either<Throwable, List<TweetApiModel>>> { | |
val response = twitterApi.search( | |
requestsIOHandler.getTokenFormatted(token), query) | |
if (requestsIOHandler.searchIsSuccessful(response)) { | |
val tweets = requestsIOHandler.getTweets(response) | |
emit(Either.right(tweets)) | |
} else { | |
emit(Either.left(EmptyResponseException())) | |
} | |
}.flowOn(taskThreading.ioDispatcher()) | |
.asObservable() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment