Skip to content

Instantly share code, notes, and snippets.

@gtomek
Forked from tymbark/concatMap.java
Created January 24, 2018 17:46
Show Gist options
  • Save gtomek/522a8e7b61561850d175f872596bd8e4 to your computer and use it in GitHub Desktop.
Save gtomek/522a8e7b61561850d175f872596bd8e4 to your computer and use it in GitHub Desktop.
@Test
public void switchMap() throws Exception {
final List<String> items = Lists.newArrayList("a", "b", "c", "d", "e", "f");
final TestScheduler scheduler = new TestScheduler();
Observable.from(items)
.concatMap( s -> {
final int delay = new Random().nextInt(10);
return Observable.just(s + "x")
.delay(delay, TimeUnit.SECONDS, scheduler);
})
.toList()
.doOnNext(System.out::println)
.subscribe();
scheduler.advanceTimeBy(1, TimeUnit.MINUTES);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment