Skip to content

Instantly share code, notes, and snippets.

@ivangodfather
Created September 12, 2020 07:42
Show Gist options
  • Save ivangodfather/53f0c521113b06398e175b3208b549bf to your computer and use it in GitHub Desktop.
Save ivangodfather/53f0c521113b06398e175b3208b549bf to your computer and use it in GitHub Desktop.
import Combine
var cancellables = Set<AnyCancellable>()
let test = [1, 2, 3, 4].publisher
.delay(for: .seconds(2), scheduler: DispatchQueue.global())
.print()
.share()
test.sink { value in
print("1: \(value)")
}.store(in: &cancellables)
test.sink { value in
print("2: \(value)")
}.store(in: &cancellables)
receive subscription: (Combine.Publishers.Delay<Combine.Publishers.Sequence<Swift.Array<Swift.Int>, Swift.Never>, __C.OS_dispatch_queue>.(unknown context at $7fff233497ac).Inner<Combine.Publishers.Print<Combine.Publishers.Delay<Combine.Publishers.Sequence<Swift.Array<Swift.Int>, Swift.Never>, __C.OS_dispatch_queue>>.(unknown context at $7fff2333cf5c).Inner<Combine.SubjectSubscriber<Combine.PassthroughSubject<Swift.Int, Swift.Never>>>>)
request unlimited
receive value: (1)
1: 1
2: 1
receive value: (2)
1: 2
2: 2
receive value: (3)
1: 3
2: 3
receive finished
receive value: (4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment