Created
June 22, 2019 10:41
-
-
Save felixvisee/31c26c4e7837746d8cea5bb007de9100 to your computer and use it in GitHub Desktop.
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
import PlaygroundSupport | |
PlaygroundPage.current.needsIndefiniteExecution = true | |
import Combine | |
import Dispatch | |
import Foundation | |
(1...10) | |
.publisher() | |
.handleEvents(receiveOutput: { print("publisher sent \($0)") }) | |
.collect(2) | |
.handleEvents(receiveOutput: { print("downstream collected \($0)") }) | |
.flatMap(maxPublishers: .max(1)) { values in | |
return Publishers.Just(values) | |
.delay(for: .seconds(1), scheduler: DispatchQueue.main) | |
.handleEvents(receiveOutput: { print("downstream delayed \($0)") }) | |
} | |
.sink(receiveCompletion: { _ in PlaygroundPage.current.finishExecution() }) { | |
print("sink received \($0)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: