@@ -4293,17 +4293,17 @@ public final Observable<T> doOnEach(final Action1<Notification<? super T>> onNot
4293
4293
Observer <T > observer = new Observer <T >() {
4294
4294
@ Override
4295
4295
public final void onCompleted () {
4296
- onNotification .call (new Notification < T > ());
4296
+ onNotification .call (Notification . createOnCompleted ());
4297
4297
}
4298
4298
4299
4299
@ Override
4300
4300
public final void onError (Throwable e ) {
4301
- onNotification .call (new Notification < T > (e ));
4301
+ onNotification .call (Notification . createOnError (e ));
4302
4302
}
4303
4303
4304
4304
@ Override
4305
4305
public final void onNext (T v ) {
4306
- onNotification .call (new Notification < T > (v ));
4306
+ onNotification .call (Notification . createOnNext (v ));
4307
4307
}
4308
4308
4309
4309
};
@@ -4387,6 +4387,39 @@ public final void onNext(T args) {
4387
4387
4388
4388
return lift (new OperatorDoOnEach <T >(observer ));
4389
4389
}
4390
+
4391
+ /**
4392
+ * Modifies an Observable so that it invokes an action when it calls {@code onCompleted} or {@code onError} <p>
4393
+ * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/doOnCompleted.png">
4394
+ * <p>
4395
+ * This differs from {@code finallyDo} in that this happens BEFORE onCompleted/onError are emitted.
4396
+ *
4397
+ * @param onTerminate
4398
+ * the action to invoke when the source Observable calls {@code onCompleted} or {@code onError}
4399
+ * @return the source Observable with the side-effecting behavior applied
4400
+ * @see <a href="https://github.com/Netflix/RxJava/wiki/Observable-Utility-Operators#wiki-dooncompleted">RxJava Wiki: doOnCompleted()</a>
4401
+ * @see <a href="http://msdn.microsoft.com/en-us/library/hh229804.aspx">MSDN: Observable.Do</a>
4402
+ */
4403
+ public final Observable <T > doOnTerminate (final Action0 onTerminate ) {
4404
+ Observer <T > observer = new Observer <T >() {
4405
+ @ Override
4406
+ public final void onCompleted () {
4407
+ onTerminate .call ();
4408
+ }
4409
+
4410
+ @ Override
4411
+ public final void onError (Throwable e ) {
4412
+ onTerminate .call ();
4413
+ }
4414
+
4415
+ @ Override
4416
+ public final void onNext (T args ) {
4417
+ }
4418
+
4419
+ };
4420
+
4421
+ return lift (new OperatorDoOnEach <T >(observer ));
4422
+ }
4390
4423
4391
4424
/**
4392
4425
* Returns an Observable that emits the single item at a specified index in a sequence of emissions from a
0 commit comments