Last active
April 29, 2016 07:13
-
-
Save binshuohu/bcb565bc3908caaf9cf24ad823a101b9 to your computer and use it in GitHub Desktop.
merge rx observable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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