Skip to content

Instantly share code, notes, and snippets.

@rizumita
Created February 9, 2020 12:47
Show Gist options
  • Save rizumita/4d76188c9936f81caa0d77bcb8c828fd to your computer and use it in GitHub Desktop.
Save rizumita/4d76188c9936f81caa0d77bcb8c828fd to your computer and use it in GitHub Desktop.
Combineのasync/awaitをライブラリ化して自作フレームワークで使ってみた。かなり良い感じ。 https://github.com/rizumita/CombineAsync #CodePiece
static func update(event: Event, context: Context) -> Async<Model> {
async { yield in
switch event {
case .increase:
context.countRepository.increase()
case .increaseAutomatically:
yield(context.countRepository.increaseAutomatically(interval: 2.0, until: context.until)
.flatMap { self.makeModelAsync(context: context) })
case .stopIncreaseAutomatically:
context.until.send(())
case .decrease:
context.countRepository.decrease()
}
yield(makeModelAsync(context: context))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment