File tree Expand file tree Collapse file tree 7 files changed +50
-87
lines changed Expand file tree Collapse file tree 7 files changed +50
-87
lines changed Original file line number Diff line number Diff line change 19
19
import rx .Observable .OnSubscribe ;
20
20
import rx .Subscriber ;
21
21
import rx .functions .Func0 ;
22
+ import rx .observers .Subscribers ;
22
23
23
24
/**
24
25
* Do not create the Observable until an Observer subscribes; create a fresh Observable on each
@@ -46,20 +47,7 @@ public void call(final Subscriber<? super T> s) {
46
47
s .onError (t );
47
48
return ;
48
49
}
49
- o .unsafeSubscribe (new Subscriber <T >(s ) {
50
- @ Override
51
- public void onNext (T t ) {
52
- s .onNext (t );
53
- }
54
- @ Override
55
- public void onError (Throwable e ) {
56
- s .onError (e );
57
- }
58
- @ Override
59
- public void onCompleted () {
60
- s .onCompleted ();
61
- }
62
- });
50
+ o .unsafeSubscribe (Subscribers .wrap (s ));
63
51
}
64
52
65
53
}
Original file line number Diff line number Diff line change 21
21
import rx .Observable .OnSubscribe ;
22
22
import rx .Scheduler .Worker ;
23
23
import rx .functions .Action0 ;
24
+ import rx .observers .Subscribers ;
24
25
25
26
/**
26
27
* Delays the subscription to the source by the given amount, running on the given scheduler.
@@ -49,20 +50,7 @@ public void call(final Subscriber<? super T> s) {
49
50
@ Override
50
51
public void call () {
51
52
if (!s .isUnsubscribed ()) {
52
- source .unsafeSubscribe (new Subscriber <T >(s ) {
53
- @ Override
54
- public void onNext (T t ) {
55
- s .onNext (t );
56
- }
57
- @ Override
58
- public void onError (Throwable e ) {
59
- s .onError (e );
60
- }
61
- @ Override
62
- public void onCompleted () {
63
- s .onCompleted ();
64
- }
65
- });
53
+ source .unsafeSubscribe (Subscribers .wrap (s ));
66
54
}
67
55
}
68
56
}, time , unit );
Original file line number Diff line number Diff line change 18
18
import rx .*;
19
19
import rx .Observable .OnSubscribe ;
20
20
import rx .functions .Func0 ;
21
+ import rx .observers .Subscribers ;
21
22
22
23
/**
23
24
* Delays the subscription until the Observable<U> emits an event.
@@ -42,20 +43,7 @@ public void call(final Subscriber<? super T> child) {
42
43
@ Override
43
44
public void onCompleted () {
44
45
// subscribe to actual source
45
- source .unsafeSubscribe (new Subscriber <T >(child ) {
46
- @ Override
47
- public void onNext (T t ) {
48
- child .onNext (t );
49
- }
50
- @ Override
51
- public void onError (Throwable e ) {
52
- child .onError (e );
53
- }
54
- @ Override
55
- public void onCompleted () {
56
- child .onCompleted ();
57
- }
58
- });
46
+ source .unsafeSubscribe (Subscribers .wrap (child ));
59
47
}
60
48
61
49
@ Override
Original file line number Diff line number Diff line change 22
22
import rx .Observable .OnSubscribe ;
23
23
import rx .exceptions .CompositeException ;
24
24
import rx .functions .*;
25
+ import rx .observers .Subscribers ;
25
26
26
27
/**
27
28
* Constructs an observable sequence that depends on a resource object.
@@ -68,20 +69,7 @@ public void call(final Subscriber<? super T> subscriber) {
68
69
observable = source ;
69
70
try {
70
71
// start
71
- observable .unsafeSubscribe (new Subscriber <T >(subscriber ) {
72
- @ Override
73
- public void onNext (T t ) {
74
- subscriber .onNext (t );
75
- }
76
- @ Override
77
- public void onError (Throwable e ) {
78
- subscriber .onError (e );
79
- }
80
- @ Override
81
- public void onCompleted () {
82
- subscriber .onCompleted ();
83
- }
84
- });
72
+ observable .unsafeSubscribe (Subscribers .from (subscriber ));
85
73
} catch (Throwable e ) {
86
74
Throwable disposeError = disposeEagerlyIfRequested (disposeOnceOnly );
87
75
if (disposeError != null )
Original file line number Diff line number Diff line change 18
18
import rx .Observable .Operator ;
19
19
import rx .Subscriber ;
20
20
import rx .functions .Action0 ;
21
+ import rx .observers .Subscribers ;
21
22
22
23
/**
23
24
* This operator modifies an {@link rx.Observable} so a given action is invoked when the {@link rx.Observable} is subscribed.
@@ -39,19 +40,6 @@ public Subscriber<? super T> call(final Subscriber<? super T> child) {
39
40
subscribe .call ();
40
41
// Pass through since this operator is for notification only, there is
41
42
// no change to the stream whatsoever.
42
- return new Subscriber <T >(child ) {
43
- @ Override
44
- public void onNext (T t ) {
45
- child .onNext (t );
46
- }
47
- @ Override
48
- public void onError (Throwable e ) {
49
- child .onError (e );
50
- }
51
- @ Override
52
- public void onCompleted () {
53
- child .onCompleted ();
54
- }
55
- };
43
+ return Subscribers .wrap (child );
56
44
}
57
45
}
Original file line number Diff line number Diff line change 18
18
import rx .Observable .Operator ;
19
19
import rx .*;
20
20
import rx .functions .Action0 ;
21
+ import rx .observers .Subscribers ;
21
22
import rx .subscriptions .Subscriptions ;
22
23
23
24
/**
@@ -41,22 +42,6 @@ public Subscriber<? super T> call(final Subscriber<? super T> child) {
41
42
42
43
// Pass through since this operator is for notification only, there is
43
44
// no change to the stream whatsoever.
44
- return new Subscriber <T >(child ) {
45
- @ Override
46
- public void onStart () {
47
- }
48
- @ Override
49
- public void onNext (T t ) {
50
- child .onNext (t );
51
- }
52
- @ Override
53
- public void onError (Throwable e ) {
54
- child .onError (e );
55
- }
56
- @ Override
57
- public void onCompleted () {
58
- child .onCompleted ();
59
- }
60
- };
45
+ return Subscribers .wrap (child );
61
46
}
62
47
}
Original file line number Diff line number Diff line change 17
17
18
18
import rx .Observer ;
19
19
import rx .Subscriber ;
20
+ import rx .annotations .Experimental ;
20
21
import rx .exceptions .OnErrorNotImplementedException ;
21
22
import rx .functions .Action0 ;
22
23
import rx .functions .Action1 ;
@@ -198,4 +199,41 @@ public final void onNext(T args) {
198
199
};
199
200
}
200
201
202
+ /**
203
+ * Returns a new {@link Subscriber} that passes all events to
204
+ * <code>subscriber</code>, has backpressure controlled by
205
+ * <code>subscriber</code> and uses the subscription list of
206
+ * <code>subscriber</code> when {@link Subscriber#add(rx.Subscription)} is
207
+ * called.
208
+ *
209
+ * @param subscriber
210
+ * the Subscriber to wrap.
211
+ *
212
+ * @return a new Subscriber that passes all events to
213
+ * <code>subscriber</code>, has backpressure controlled by
214
+ * <code>subscriber</code> and uses <code>subscriber</code> to
215
+ * manage unsubscription.
216
+ *
217
+ */
218
+ @ Experimental
219
+ public static <T > Subscriber <T > wrap (final Subscriber <? super T > subscriber ) {
220
+ return new Subscriber <T >(subscriber ) {
221
+
222
+ @ Override
223
+ public void onCompleted () {
224
+ subscriber .onCompleted ();
225
+ }
226
+
227
+ @ Override
228
+ public void onError (Throwable e ) {
229
+ subscriber .onError (e );
230
+ }
231
+
232
+ @ Override
233
+ public void onNext (T t ) {
234
+ subscriber .onNext (t );
235
+ }
236
+
237
+ };
238
+ }
201
239
}
You can’t perform that action at this time.
0 commit comments