Skip to content

Instantly share code, notes, and snippets.

@ytRino
Forked from keima/AsyncOrderSafeObservableTest.java
Last active September 29, 2017 07:56
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 ytRino/658c44b421704b80c95fc53ace78ab6b to your computer and use it in GitHub Desktop.
Save ytRino/658c44b421704b80c95fc53ace78ab6b to your computer and use it in GitHub Desktop.
public void concatEager() {
final TestSubscriber<List<String>> testSubscriber = new TestSubscriber<>();
final long startTime = new Date().getTime();
System.out.println("Start.");
Observable.concatEager( //
asyncObservable("uno", 4), //
asyncObservable("dos", 3), //
asyncObservable("tres", 2), //
asyncObservable("cuatro", 1))
.toList()
.doOnNext(strings -> System.out.println("onNext: " + strings))
.doOnCompleted(() -> System.out.println("onCompleted"))
.doOnError(Throwable::printStackTrace)
.subscribe(testSubscriber);
testSubscriber.awaitTerminalEvent();
testSubscriber.assertCompleted();
testSubscriber.assertNoErrors();
final long endTime = new Date().getTime();
System.out.println("End: " + (endTime - startTime) + "ms");
}
private Observable<String> asyncObservable(String msg, int wait) {
return Observable.just(msg)
.delay(wait, TimeUnit.SECONDS, Schedulers.newThread())
.doOnNext(s -> System.out.println("onNext(src) " + s));
}
12-16 20:08:26.142 I/System.out: Start.
12-16 20:08:27.148 I/System.out: onNext(src) cuatro
12-16 20:08:28.148 I/System.out: onNext(src) tres
12-16 20:08:29.147 I/System.out: onNext(src) dos
12-16 20:08:30.147 I/System.out: onNext(src) uno
12-16 20:08:30.149 I/System.out: onNext: [uno, dos, tres, cuatro]
12-16 20:08:30.149 I/System.out: onCompleted
12-16 20:08:30.158 I/System.out: End: 4015ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment