File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
src/com/blankj/custom/rxjava Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1
1
package com .blankj .custom .rxjava ;
2
2
3
3
public class Observable <T > {
4
+ final OnSubscribe <T > onSubscribe ;
5
+
6
+ private Observable (OnSubscribe <T > onSubscribe ) {
7
+ this .onSubscribe = onSubscribe ;
8
+ }
9
+
10
+ public static <T > Observable <T > create (OnSubscribe <T > onSubscribe ) {
11
+ return new Observable <T >(onSubscribe );
12
+ }
13
+
14
+ public void subscribe (Subscriber <? super T > subscriber ) {
15
+ subscriber .onStart ();
16
+ onSubscribe .call (subscriber );
17
+ }
18
+
19
+ public interface OnSubscribe <T > {
20
+ void call (Subscriber <? super T > subscriber );
21
+ }
4
22
5
23
}
Original file line number Diff line number Diff line change
1
+ package com .blankj .custom .rxjava ;
2
+
3
+ public class Test {
4
+ public static void main (String [] args ) {
5
+ Observable .create (new Observable .OnSubscribe <Integer >() {
6
+ @ Override
7
+ public void call (Subscriber <? super Integer > subscriber ) {
8
+ for (int i = 0 ; i < 10 ; i ++) {
9
+ subscriber .onNext (i );
10
+ }
11
+ }
12
+ }).subscribe (new Subscriber <Integer >() {
13
+ @ Override
14
+ public void onCompleted () {
15
+
16
+ }
17
+ @ Override
18
+ public void onError (Throwable t ) {
19
+
20
+ }
21
+ @ Override
22
+ public void onNext (Integer var1 ) {
23
+ System .out .println (var1 );
24
+ }
25
+ });
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments