Last active
May 25, 2017 07:05
-
-
Save tymbark/ea57978a627be20cab29e35fc8036c80 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@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