Skip to content

Instantly share code, notes, and snippets.

@eunjin3786
Last active June 28, 2019 05:18
Show Gist options
  • Save eunjin3786/0a9a1536d77de08667ee8506c0eb4e9f to your computer and use it in GitHub Desktop.
Save eunjin3786/0a9a1536d77de08667ee8506c0eb4e9f to your computer and use it in GitHub Desktop.
let subject = CurrentValueSubject<String, Error>.init("Init Value")
subject.send("Is anyone listening?")
let subcription1 = subject.sink(receiveCompletion: {
print("1) \($0)")
}, receiveValue: {
print("1) \($0)")
})
let subscription2 = subject.sink(receiveCompletion: {
print("2) \($0)")
}, receiveValue: {
print("2) \($0)")
})
subject.send("Hello")
subject.send(completion: .finished)
subject.send("Is alive?")
<Output>
1) Init Value
2) Init Value
1) Hello
2) Hello
1) finished
2) finished
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment