forked from PacktPublishing/Learning-RxJava-Second-Edition
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCh6_02.java
More file actions
26 lines (23 loc) · 776 Bytes
/
Copy pathCh6_02.java
File metadata and controls
26 lines (23 loc) · 776 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
import io.reactivex.rxjava3.core.Observable;
import java.util.concurrent.ThreadLocalRandom;
public class Ch6_02 {
public static void main(String[] args) {
Observable.just("Alpha", "Beta", "Gamma")
.map(s -> intenseCalculation((s)))
.subscribe(System.out::println);
Observable.range(1, 3)
.map(s -> intenseCalculation((s)))
.subscribe(System.out::println);
}
private static <T> T intenseCalculation(T value) {
sleep(ThreadLocalRandom.current().nextInt(3000));
return value;
}
private static void sleep(long millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}