Skip to content

Instantly share code, notes, and snippets.

@zsoltk
Created October 9, 2018 23:04
Show Gist options
  • Save zsoltk/6426b6b5dc3567988d47f494605af23a to your computer and use it in GitHub Desktop.
Save zsoltk/6426b6b5dc3567988d47f494605af23a to your computer and use it in GitHub Desktop.
val output: PublishSubject<String> = PublishSubject.create()
val input: Consumer<String> = Consumer { System.out.println(it) }
val lifecycle = ManualLifecycle()
val binder = Binder(lifecycle)
binder.bind(output to input)
output.onNext("1")
lifecycle.begin()
output.onNext("2")
output.onNext("3")
lifecycle.end()
output.onNext("4")
lifecycle.begin()
output.onNext("5")
output.onNext("6")
lifecycle.end()
output.onNext("7")
// will print:
// 2
// 3
// 5
// 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment