Skip to content

Instantly share code, notes, and snippets.

@max6363
Created January 20, 2022 12:49
Show Gist options
  • Save max6363/00e3de071dff4d0b3cc0b631405f4f79 to your computer and use it in GitHub Desktop.
Save max6363/00e3de071dff4d0b3cc0b631405f4f79 to your computer and use it in GitHub Desktop.
import Combine
import Foundation
import PlaygroundSupport
var subscription: Cancellable? = 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()
subscription = nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment