Skip to content

Commit e7d6fef

Browse files
committed
update
1 parent 41f6a5b commit e7d6fef

File tree

1 file changed

+58
-0
lines changed
  • dev_projects/RxJava/RxJava/src/main/java/com/yen/courseV1

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.yen.courseV1;
2+
3+
// https://youtu.be/yWdl58IXuPQ?si=NfR3e0V24xWjk1Sc
4+
5+
import java.awt.event.ActionEvent;
6+
import java.util.Scanner;
7+
import java.util.concurrent.TimeUnit;
8+
import javax.swing.*;
9+
import rx.Completable;
10+
import rx.Observable;
11+
import rx.functions.Action0;
12+
13+
public class part3 {
14+
public static void main(String[] args) {
15+
16+
// Observable.range
17+
Observable<Integer> observable = Observable.range(2, 5);
18+
19+
observable.subscribe(
20+
item -> {
21+
System.out.println(item);
22+
});
23+
24+
// Observable.interval
25+
Observable<Long> intervalObservable = Observable.interval(1, TimeUnit.SECONDS);
26+
27+
// intervalObservable.subscribe(item -> {
28+
// System.out.println(item);
29+
// });
30+
31+
// Observable.interval
32+
Observable<Long> timeObservable = Observable.timer(5, TimeUnit.SECONDS);
33+
34+
timeObservable.subscribe(
35+
item -> {
36+
System.out.println("5 sec passed " + item);
37+
});
38+
39+
//Action action2 = () -> System.out.println("hello world!!");
40+
Action action =
41+
new AbstractAction() {
42+
@Override
43+
public void actionPerformed(ActionEvent e) {
44+
System.out.println("ActionEvent = " + e);
45+
}
46+
};
47+
48+
Completable completable = Completable.fromAction((Action0) action);
49+
50+
completable.subscribe(() -> {
51+
System.out.println("---> Action ends");
52+
});
53+
54+
55+
// to avoid program completed while intervalObservable, timeObservable are still running
56+
new Scanner(System.in).nextLine();
57+
}
58+
}

0 commit comments

Comments
 (0)