Created
January 20, 2022 12:45
-
-
Save max6363/f82d7cb6b8803d17fb62d77cc9a670cc 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 Combine | |
import Foundation | |
import PlaygroundSupport | |
let subscription = Timer.publish(every: 1, on: .main, in: .common) | |
.autoconnect() | |
.print("data stream") | |
.sink { output in | |
print("finished stream with : \(output)") | |
} receiveValue: { value in | |
print("receive value: \(value)") | |
} | |
RunLoop.main.schedule(after: .init(Date(timeIntervalSinceNow: 5))) { | |
print(" - cancel subscription") | |
subscription.cancel() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment