Created
October 18, 2020 01:52
-
-
Save masakih/01a93dce36421080f63e8c34285f18cd to your computer and use it in GitHub Desktop.
だめ #CodePiece
This file contains hidden or 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
| (0...3) | |
| .map { i -> AnyPublisher<Int, Never> in | |
| Future<Int, Never> { promise in | |
| print("start", i) | |
| sleep(UInt32([0, 2, 3, 5].randomElement()!)) | |
| print("end", 1) | |
| promise(.success(i * 2)) | |
| } | |
| .eraseToAnyPublisher() | |
| } | |
| .reduce(Empty<Int, Never>().eraseToAnyPublisher()) { (p, pp) in | |
| p.merge(with: pp).eraseToAnyPublisher() | |
| } | |
| .sink { (i) in | |
| print(i) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment