Created
October 18, 2020 02:20
-
-
Save masakih/1cdf24f161d5e7470e4c7cbc8fb7ca73 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) | |
| .publisher | |
| .flatMap { i -> AnyPublisher<Int, Never> in | |
| Future<Int, Never> { promise in | |
| DispatchQueue.global().async { | |
| print("start", i, "----", Thread.current) | |
| sleep(UInt32([0, 2, 3, 5].randomElement()!)) | |
| print("end", i) | |
| promise(.success(i * 2)) | |
| } | |
| } | |
| .eraseToAnyPublisher() | |
| } | |
| .collect() | |
| .sink { (i) in | |
| print(i) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment