forked from PacktPublishing/Learning-RxJava-Second-Edition
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh8_01.java
More file actions
29 lines (25 loc) · 741 Bytes
/
Copy pathCh8_01.java
File metadata and controls
29 lines (25 loc) · 741 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
26
27
28
29
import io.reactivex.rxjava3.core.Observable;
public class Ch8_01 {
public static void main(String[] args) {
Observable.range(1, 999_999_999)
.map(MyItem::new)
.subscribe(myItem -> {
sleep(5000);
System.out.println("Received MyItem " + myItem.id);
});
}
static void sleep(long milliseconds) {
try {
Thread.sleep(milliseconds);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
static final class MyItem {
final int id;
MyItem(int id) {
this.id = id;
System.out.println("Constructing MyItem " + id);
}
}
}