Skip to content

Instantly share code, notes, and snippets.

@tymbark
Last active May 25, 2017 07:05
Show Gist options
  • Save tymbark/ea57978a627be20cab29e35fc8036c80 to your computer and use it in GitHub Desktop.
Save tymbark/ea57978a627be20cab29e35fc8036c80 to your computer and use it in GitHub Desktop.
@Test
public void flatMapAndConcatMapCompare() throws Exception {
final List<String> items = Lists.newArrayList("a", "b", "c", "d", "e", "f");
final TestScheduler scheduler1 = new TestScheduler();
final TestScheduler scheduler2 = new TestScheduler();
Observable.from(items)
.flatMap(s -> Observable.just(s + "x")
.delay(5, TimeUnit.SECONDS, scheduler1)
.doOnNext(str -> System.out.print(scheduler1.now() + " ")))
.toList()
.doOnNext(strings -> System.out.println("\nEND:" + scheduler1.now()))
.subscribe();
scheduler1.advanceTimeBy(1, TimeUnit.MINUTES);
Observable.from(items)
.concatMap(s -> Observable.just(s + "x")
.delay(5, TimeUnit.SECONDS, scheduler2)
.doOnNext(str -> System.out.print(scheduler2.now() + " ")))
.toList()
.doOnNext(strings -> System.out.println("\nEND:" + scheduler2.now()))
.subscribe();
scheduler2.advanceTimeBy(1, TimeUnit.MINUTES);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment