-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObservableSubscriber.java
More file actions
42 lines (32 loc) · 1.08 KB
/
Copy pathObservableSubscriber.java
File metadata and controls
42 lines (32 loc) · 1.08 KB
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
package rxjava;
import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.Subscription;
public class ObservableSubscriber {
public static void main(String[] args) {
Observable<Integer> observableString = Observable.create(new Observable.OnSubscribe<Integer>() {
@Override
public void call(Subscriber<? super Integer> observer) {
for (int i = 0; i < 5; i++) {
observer.onNext(i);
}
observer.onCompleted();
}
});
Subscription subscriptionPrint = observableString.subscribe(new Observer<Integer>() {
@Override
public void onCompleted() {
System.out.println("Observable completed");
}
@Override
public void onError(Throwable e) {
System.out.println("Oh no! Something wrong happend!");
}
@Override
public void onNext(Integer integer) {
System.out.println("Item is : " + integer);
}
});
}
}