-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample4.java
More file actions
43 lines (36 loc) · 1.25 KB
/
example4.java
File metadata and controls
43 lines (36 loc) · 1.25 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
43
import rx.Observable;
import rx.Subscriber;
import rx.functions.Action1;
/**
* Filtering an asynchronous {@link Observable} using the built-in skip() method.
*
* Asynchronous simply means executing it on a separate thread.
*/
public class example4 {
public static void main(String[] args){
Observable asyncObservable = Observable.create(new Observable.OnSubscribe() {
@Override
public void call(Object subscriber) {
final Subscriber mySubscriber = (Subscriber)subscriber;
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
for(int i = 0 ; i < 10 ; i++){
if(!mySubscriber.isUnsubscribed()){
mySubscriber.onNext("Pushing value from async thread" + i);
}
}
}
});
thread.start();
}
});
//Skip the first 5 emitted items.
asyncObservable.skip(5).subscribe(new Action1<String>() {
@Override
public void call(String s) {
System.out.println(s);
}
});
}
}