forked from PacktPublishing/Learning-RxJava-Second-Edition
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh2_18.java
More file actions
25 lines (23 loc) · 716 Bytes
/
Copy pathCh2_18.java
File metadata and controls
25 lines (23 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import io.reactivex.rxjava3.core.Observable;
import java.util.concurrent.TimeUnit;
public class Ch2_18 {
public static void main(String[] args) {
Observable<Long> seconds =
Observable.interval(1, TimeUnit.SECONDS);
//Observer 1
seconds.subscribe(l -> System.out.println("Observer 1: " + l));
//sleep 3 seconds
sleep(3000);
//Observer 2
seconds.subscribe(l -> System.out.println("Observer 2: " + l));
//sleep 3 seconds
sleep(3000);
}
private static void sleep(int millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}