Skip to content

Instantly share code, notes, and snippets.

@KowalczykBartek
Created December 27, 2015 21:20
Show Gist options
  • Save KowalczykBartek/6677e60223daa6a14e15 to your computer and use it in GitHub Desktop.
Save KowalczykBartek/6677e60223daa6a14e15 to your computer and use it in GitHub Desktop.
sample of rxjava repeatWhen
public static void main(String... args) {
AtomicInteger a = new AtomicInteger();
Observable.just(1, 2, 3, 4, 5, 6, 7, 8)
.repeatWhen(notification -> {
return notification.flatMap(o -> {
System.out.println("'repeatWhen'");
if(a.getAndAdd(1) < 10){
return Observable.just(o).delay(1,TimeUnit.SECONDS);
}else{
return Observable.empty();
}
});
})//
.subscribe(System.out::println);
while (true) ;
}
@canwe
Copy link

canwe commented Mar 14, 2017

Why should I need to put while (true) ; in the end? Isn't repeatWhen working without this?

@andschdk
Copy link

Why should I need to put while (true) ; in the end? Isn't repeatWhen working without this?

This is to keep the program running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment