Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active April 28, 2020 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasdev/f0730d645025ffb5a385766159f34f22 to your computer and use it in GitHub Desktop.
Save jasdev/f0730d645025ffb5a385766159f34f22 to your computer and use it in GitHub Desktop.
Check `untilOutputFrom`’s demand count.
import Combine
import PlaygroundSupport
var subscriptions = Set<AnyCancellable>()
[1, 2, 3]
.publisher
.prefix(
untilOutputFrom: Just(4)
.print() /// (1) To log out lifecycle events.
).sink(receiveValue: { print($0) })
.store(in: &subscriptions)
PlaygroundPage.current.needsIndefiniteExecution = true
/// (2) Output. Note that only a max of one value is requested from `Just(4)`.
/// ```none
/// receive subscription: (Just)
/// request max: (1)
/// receive value: (4)
/// receive cancel
/// receive finished
/// ```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment