Skip to content

Commit 0566f9c

Browse files
IntervalDemo
1 parent 0603e39 commit 0566f9c

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package rx;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.concurrent.TimeUnit;
6+
7+
import org.junit.Ignore;
8+
import org.junit.Test;
9+
10+
import rx.util.functions.Action0;
11+
import rx.util.functions.Action1;
12+
13+
@Ignore // since this doesn't do any automatic testing
14+
public class IntervalDemo {
15+
16+
@Test public void demoInterval() throws Exception {
17+
testLongObservable(Observable.interval(500, TimeUnit.MILLISECONDS).take(4), "demoInterval");
18+
}
19+
20+
public void testLongObservable(Observable<Long> o, final String testname) throws Exception {
21+
final List<Long> l = new ArrayList<Long>();
22+
Action1<Long> onNext = new Action1<Long>() {
23+
public void call(Long i) {
24+
l.add(i);
25+
System.out.println(testname + " got " + i);
26+
}
27+
};
28+
Action1<Throwable> onError = new Action1<Throwable>() {
29+
public void call(Throwable t) { t.printStackTrace(); }
30+
};
31+
Action0 onComplete = new Action0() {
32+
public void call() {
33+
System.out.println(testname + " complete");
34+
}
35+
};
36+
o.subscribe(onNext, onError, onComplete);
37+
38+
// need to wait, otherwise JUnit kills the thread of interval()
39+
Thread.sleep(2500);
40+
}
41+
42+
}

0 commit comments

Comments
 (0)