Skip to content

Instantly share code, notes, and snippets.

@binshuohu
Last active April 29, 2016 07:13
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 binshuohu/bcb565bc3908caaf9cf24ad823a101b9 to your computer and use it in GitHub Desktop.
Save binshuohu/bcb565bc3908caaf9cf24ad823a101b9 to your computer and use it in GitHub Desktop.
merge rx observable
import rx.lang.scala._
import rx.lang.scala.subjects.ReplaySubject
import scala.concurrent.Promise
import scala.concurrent.ExecutionContext.Implicits.global
val r = ReplaySubject[Int]()
r.onNext(1)
r.onNext(2)
r.onNext(3)
val promise = Promise[List[Int]]()
val zz = Observable.defer(Observable[Int] { observer =>
r.doOnNext(observer.onNext).subscribe()
observer.onCompleted()
})
.subscribeOn(schedulers.NewThreadScheduler()).toList
.subscribe(l => promise.success(l.reverse))
promise.future map println
//I wish it prints [1 2 3]
r.onNext(4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment