Skip to content

Instantly share code, notes, and snippets.

@javipacheco
Created November 9, 2017 16:09
Show Gist options
  • Save javipacheco/243a5ae15454db7a4eefb5dfce7a6e4e to your computer and use it in GitHub Desktop.
Save javipacheco/243a5ae15454db7a4eefb5dfce7a6e4e to your computer and use it in GitHub Desktop.
NewsActor
class NewsActors(val apiService: ApiService, val uiService: NewsUiService) {
val mainActor = actor<Commands> {
var newsState: States.NewsState = States.NewsState(ListKW.empty())
for (msg in channel) {
when (msg) {
is Commands.NewsGetItemsCommand ->
ServiceMonad().binding {
uiService.showLoading()
val news = apiService.getNews().bind()
newsState = newsState.copy(items = news.combineK(newsState.items))
uiService.showNews(news).bind()
yields(Unit)
}.ev().fold({ ex ->
when(ex) {
is AkmeException.ApiException ->
notificationActor.sendBlocking(Notifications.NewsNotLoadedNotification)
is AkmeException.UiException ->
notificationActor.sendBlocking(Notifications.NewsUiErrorNotification)
}
}, {})
is Commands.NewsShowMessageCommand ->
uiService.showMessage(msg.item)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment