Skip to content

Instantly share code, notes, and snippets.

@raulh82vlc
Last active June 15, 2020 18:39
Show Gist options
  • Save raulh82vlc/6f68f75e91ee1666ddb1fee094c3805c to your computer and use it in GitHub Desktop.
Save raulh82vlc/6f68f75e91ee1666ddb1fee094c3805c to your computer and use it in GitHub Desktop.
SearchTweetUseCase Flow collection
private val scope = CoroutineScope(taskThreading.uiDispatcher() + SupervisorJob())
@ExperimentalCoroutinesApi
override fun execute(query: String, callbackInput: SearchCallback?) {
callback = callbackInput
callback?.onShowLoader()
scope.launch {
repository.searchTweet(query)
.catch { error ->
// error handling
onError(error)
}.collect { tweets ->
// UI actions for each stream
onSuccess(tweets)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment