Skip to content

Instantly share code, notes, and snippets.

@Thomvis
Created March 6, 2020 21:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thomvis/9e03f510f74fe95b72050876f9485115 to your computer and use it in GitHub Desktop.
Save Thomvis/9e03f510f74fe95b72050876f9485115 to your computer and use it in GitHub Desktop.
let timer = Timer.publish(every: 1.0, on: RunLoop.main, in: .common)
.autoconnect()
.prepend(Date())
.map { $0.timeIntervalSince1970 }
.lane("shared timer")
.share()
.lane("timer")
timer
.sink { print($0) }.store(in: &cancellable)
timer
.filter { Int($0) % 2 == 0 }
.lane("even")
.sink { print("Even: \($0)") }.store(in: &cancellable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment