Skip to content

Instantly share code, notes, and snippets.

@cornerman
Created July 10, 2018 09:35
Show Gist options
  • Save cornerman/cb136eadd9e9ebddf137c5dd701cb8f6 to your computer and use it in GitHub Desktop.
Save cornerman/cb136eadd9e9ebddf137c5dd701cb8f6 to your computer and use it in GitHub Desktop.
scala> val subject = PublishSubject[Int]()
subject: monix.reactive.subjects.PublishSubject[Int] = monix.reactive.subjects.PublishSubject@5e470323
scala> val behaviorObs = subject.behavior(1)
behaviorObs: monix.reactive.observables.ConnectableObservable[Int] = monix.reactive.observables.ConnectableObservable$$anon$1@253df626
scala> subject.foreach { o => println("subject: " + o) }
res0: monix.execution.CancelableFuture[Unit] = Async(Future(<not completed>),monix.execution.Cancelable$CancelableTask@4a1ebd18)
scala> behaviorObs.foreach { o => println("behaviorObs: " + o) }
behaviorObs: 1
res1: monix.execution.CancelableFuture[Unit] = Async(Future(<not completed>),monix.execution.Cancelable$CancelableTask@3e4d8061)
scala> subject.onNext(-1)
subject: -1
res2: scala.concurrent.Future[monix.execution.Ack] = Continue
scala> behaviorObs.connect
res4: monix.execution.Cancelable = monix.execution.Cancelable$CancelableTask@17af5abf
scala> subject.onNext(-2)
subject: -2
behaviorObs: -2
res5: scala.concurrent.Future[monix.execution.Ack] = Continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment