Created
October 1, 2018 15:08
-
-
Save CoderJava/ec4f5f813d2dce663aa561588ac81a63 to your computer and use it in GitHub Desktop.
Interval Operator RxJava
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class RxOperatorInterval { | |
| public static void main(String[] args) throws InterruptedException { | |
| CountDownLatch countDownLatch = new CountDownLatch(1); | |
| Observable.interval(1000 * 2, TimeUnit.MILLISECONDS) | |
| .subscribe(new Observer<Long>() { | |
| @Override | |
| public void onSubscribe(Disposable d) { | |
| System.out.println("onSubscribe"); | |
| } | |
| @Override | |
| public void onNext(Long count) { | |
| String now = new SimpleDateFormat("HH:mm:ss", Locale.US).format(new Date()); | |
| System.out.println(now + " onNext: " + count); | |
| if (count == 5) { | |
| onComplete(); | |
| } | |
| } | |
| @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