Skip to content

Instantly share code, notes, and snippets.

@max6363
Created January 20, 2022 12:45
Show Gist options
  • Save max6363/f82d7cb6b8803d17fb62d77cc9a670cc to your computer and use it in GitHub Desktop.
Save max6363/f82d7cb6b8803d17fb62d77cc9a670cc to your computer and use it in GitHub Desktop.
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