Skip to content

Instantly share code, notes, and snippets.

@maiconhellmann
Last active November 4, 2020 23:22
Show Gist options
  • Save maiconhellmann/3d84b4f5220af375aefae68d483cc8d3 to your computer and use it in GitHub Desktop.
Save maiconhellmann/3d84b4f5220af375aefae68d483cc8d3 to your computer and use it in GitHub Desktop.
Timer task in RxJava kotlin/java
val subscription = Observable.interval(0, 5, TimeUnit.SECONDS)
.timeInterval()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe {
//TODO
}
Disposable timerTaskSubscription = Observable.interval(0, 30, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(new Consumer<Long>() {
@Override
public void accept(Long aLong) throws Exception {
//TODO onNext
}
},
new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
//TODO onError
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment