@@ -87,21 +87,21 @@ public interface CompletableTransformer extends Func1<Completable, Completable>
87
87
}
88
88
89
89
/** Single instance of a complete Completable. */
90
- static final Completable COMPLETE = create (new CompletableOnSubscribe () {
90
+ static final Completable COMPLETE = new Completable (new CompletableOnSubscribe () {
91
91
@ Override
92
92
public void call (CompletableSubscriber s ) {
93
93
s .onSubscribe (Subscriptions .unsubscribed ());
94
94
s .onCompleted ();
95
95
}
96
- });
96
+ }, true ); // hook is handled in complete()
97
97
98
98
/** Single instance of a never Completable. */
99
- static final Completable NEVER = create (new CompletableOnSubscribe () {
99
+ static final Completable NEVER = new Completable (new CompletableOnSubscribe () {
100
100
@ Override
101
101
public void call (CompletableSubscriber s ) {
102
102
s .onSubscribe (Subscriptions .unsubscribed ());
103
103
}
104
- });
104
+ }, true ); // hook is handled in never()
105
105
106
106
/**
107
107
* Returns a Completable which terminates as soon as one of the source Completables
@@ -311,7 +311,11 @@ public void onSubscribe(Subscription d) {
311
311
* @return a Completable instance that completes immediately
312
312
*/
313
313
public static Completable complete () {
314
- return COMPLETE ;
314
+ CompletableOnSubscribe cos = RxJavaHooks .onCreate (COMPLETE .onSubscribe );
315
+ if (cos == COMPLETE .onSubscribe ) {
316
+ return COMPLETE ;
317
+ }
318
+ return new Completable (cos , true );
315
319
}
316
320
317
321
/**
@@ -734,7 +738,11 @@ public static Completable mergeDelayError(Observable<? extends Completable> sour
734
738
* @return the singleton instance that never calls onError or onComplete
735
739
*/
736
740
public static Completable never () {
737
- return NEVER ;
741
+ CompletableOnSubscribe cos = RxJavaHooks .onCreate (NEVER .onSubscribe );
742
+ if (cos == NEVER .onSubscribe ) {
743
+ return NEVER ;
744
+ }
745
+ return new Completable (cos , true );
738
746
}
739
747
740
748
/**
@@ -975,7 +983,18 @@ public void call() {
975
983
protected Completable (CompletableOnSubscribe onSubscribe ) {
976
984
this .onSubscribe = RxJavaHooks .onCreate (onSubscribe );
977
985
}
978
-
986
+
987
+ /**
988
+ * Constructs a Completable instance with the given onSubscribe callback without calling the onCreate
989
+ * hook.
990
+ * @param onSubscribe the callback that will receive CompletableSubscribers when they subscribe,
991
+ * not null (not verified)
992
+ * @param useHook if false, RxJavaHooks.onCreate won't be called
993
+ */
994
+ private Completable (CompletableOnSubscribe onSubscribe , boolean useHook ) {
995
+ this .onSubscribe = useHook ? RxJavaHooks .onCreate (onSubscribe ) : onSubscribe ;
996
+ }
997
+
979
998
/**
980
999
* Returns a Completable that emits the a terminated event of either this Completable
981
1000
* or the other Completable whichever fires first.
0 commit comments