Skip to content

Instantly share code, notes, and snippets.

@hilfritz
Created December 7, 2018 09:02
Show Gist options
  • Save hilfritz/18776d94d4c6d113c30cde9ed4a04f10 to your computer and use it in GitHub Desktop.
Save hilfritz/18776d94d4c6d113c30cde9ed4a04f10 to your computer and use it in GitHub Desktop.
Android: Rxjava RxAndroid Countdown timer
//source: https://github.com/ReactiveX/RxJava/issues/3505
####Emit each item 5 seconds after the previous item:
List<Integer> list = new ArrayList<>(Arrays.asList(1, 2, 3, 4, 5, 6));
Observable
.interval(5, TimeUnit.SECONDS)
.map(i -> list.get(i.intValue()))
.take(list.size())
.toBlocking()
.subscribe(System.out::println)
;
####Emit everything after 5 seconds passed:
Observable
.from(list)
.delay(5, TimeUnit.SECONDS)
.toBlocking()
.subscribe(System.out::println);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment