Created
February 9, 2020 12:47
-
-
Save rizumita/4d76188c9936f81caa0d77bcb8c828fd to your computer and use it in GitHub Desktop.
Combineのasync/awaitをライブラリ化して自作フレームワークで使ってみた。かなり良い感じ。 https://github.com/rizumita/CombineAsync #CodePiece
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
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