-
Notifications
You must be signed in to change notification settings - Fork 119
/
Copy pathCreatingObservablesUsingVariousFactoryMethods.java
59 lines (42 loc) · 1.38 KB
/
CreatingObservablesUsingVariousFactoryMethods.java
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.packtpub.reactive.chapter03;
import static com.packtpub.reactive.common.Helpers.subscribePrint;
import java.util.concurrent.TimeUnit;
import rx.Observable;
import com.packtpub.reactive.common.Program;
/**
* Demonstrates using Observable.interval, Observable.timer, Observable.error,
* Observable.never, Observable.empty and Observable.range for Obsevable creation.
*
* @author meddle
*/
public class CreatingObservablesUsingVariousFactoryMethods implements Program {
@Override
public String name() {
return "A few factory methods for creating Observables";
}
@Override
public int chapter() {
return 3;
}
@Override
public void run() {
subscribePrint(Observable.interval(500L, TimeUnit.MILLISECONDS),
"Interval Observable");
subscribePrint(Observable.timer(0L, 1L, TimeUnit.SECONDS),
"Timed Interval Observable");
subscribePrint(Observable.timer(1L, TimeUnit.SECONDS),
"Timer Observable");
subscribePrint(Observable.error(new Exception("Test Error!")),
"Error Observable");
subscribePrint(Observable.empty(), "Empty Observable");
subscribePrint(Observable.never(), "Never Observable");
subscribePrint(Observable.range(1, 10), "Range Observable");
try {
Thread.sleep(2000L);
} catch (InterruptedException e) {
}
}
public static void main(String[] args) {
new CreatingObservablesUsingVariousFactoryMethods().run();
}
}