Skip to content

Instantly share code, notes, and snippets.

@MartinHH
Last active December 15, 2018 15:37
Show Gist options
  • Save MartinHH/6977ee66963e438eaf9a4d8f6314893b to your computer and use it in GitHub Desktop.
Save MartinHH/6977ee66963e438eaf9a4d8f6314893b to your computer and use it in GitHub Desktop.
RxScala vs Monix(3.0.0-RC2): behavior of SwitchMap when "parent" Observable completes
package example
import monix.execution.Ack
object Main {
def main(args: Array[String]): Unit = {
implicit val s = monix.execution.schedulers.TestScheduler()
val parent = monix.reactive.subjects.PublishSubject[Int]()
val child = monix.reactive.subjects.PublishSubject[Int]()
val o = parent.switchMap(x => child.map(x -> _))
o.subscribe{ u =>
print(u)
Ack.Continue
}
parent.onNext(1)
child.onNext(1)
parent.onComplete()
child.onNext(2)
// prints "(1, 1)" - in RxScala, this would print "(1,1)(1,2)"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment