Skip to content

Instantly share code, notes, and snippets.

@CoderJava
Created October 1, 2018 15:44
Show Gist options
  • Select an option

  • Save CoderJava/8239d166e19a089709f940e9ea2e21b6 to your computer and use it in GitHub Desktop.

Select an option

Save CoderJava/8239d166e19a089709f940e9ea2e21b6 to your computer and use it in GitHub Desktop.
Operator timer RxJava
public class RxOperatorTimer {
public static void main(String[] args) throws InterruptedException {
CountDownLatch countDownLatch = new CountDownLatch(1);
Observable.timer(1000 * 2, TimeUnit.MILLISECONDS)
.subscribe(new Observer<Long>() {
@Override
public void onSubscribe(Disposable d) {
System.out.println("onSubscribe");
}
@Override
public void onNext(Long count) {
System.out.println("onNext " + count);
}
@Override
public void onError(Throwable e) {
System.out.println("onError");
}
@Override
public void onComplete() {
System.out.println("onComplete");
countDownLatch.countDown();
}
});
countDownLatch.await();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment