@@ -3592,6 +3592,28 @@ trait Observable[+T]
3592
3592
toScalaObservable[T ](asJavaObservable.doOnEach(Observer (onNext, onError,onCompleted)))
3593
3593
}
3594
3594
3595
+ /**
3596
+ * Modifies the source `Observable` so that it invokes the given action when it is subscribed from
3597
+ * its subscribers. Each subscription will result in an invocation of the given action except when the
3598
+ * source `Observable` is reference counted, in which case the source `Observable` will invoke
3599
+ * the given action for the first subscription.
3600
+ * <p>
3601
+ * <img width="640" height="390" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/doOnSubscribe.png" alt="">
3602
+ * <dl>
3603
+ * <dt><b>Scheduler:</b></dt>
3604
+ * <dd>`onSubscribe` does not operate by default on a particular `Scheduler`.</dd>
3605
+ * </dl>
3606
+ *
3607
+ * @param onSubscribe
3608
+ * the action that gets called when an observer subscribes to this `Observable`
3609
+ * @return the source `Observable` modified so as to call this Action when appropriate
3610
+ * @see <a href="https://github.com/Netflix/RxJava/wiki/Observable-Utility-Operators#doonsubscribe">RxJava wiki: doOnSubscribe</a>
3611
+ * @since 0.20
3612
+ */
3613
+ def doOnSubscribe (onSubscribe : => Unit ): Observable [T ] = {
3614
+ toScalaObservable[T ](asJavaObservable.doOnSubscribe(() => onSubscribe))
3615
+ }
3616
+
3595
3617
/**
3596
3618
* Modifies an Observable so that it invokes an action when it calls `onCompleted` or `onError`.
3597
3619
* <p>
@@ -3608,6 +3630,28 @@ trait Observable[+T]
3608
3630
toScalaObservable[T ](asJavaObservable.doOnTerminate(() => onTerminate))
3609
3631
}
3610
3632
3633
+ /**
3634
+ * Modifies the source `Observable` so that it invokes the given action when it is unsubscribed from
3635
+ * its subscribers. Each un-subscription will result in an invocation of the given action except when the
3636
+ * source `Observable` is reference counted, in which case the source `Observable` will invoke
3637
+ * the given action for the very last un-subscription.
3638
+ * <p>
3639
+ * <img width="640" height="310" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/doOnUnsubscribe.png" alt="">
3640
+ * <dl>
3641
+ * <dt><b>Scheduler:</b></dt>
3642
+ * <dd>`doOnUnsubscribe` does not operate by default on a particular `Scheduler`.</dd>
3643
+ * </dl>
3644
+ *
3645
+ * @param onUnsubscribe
3646
+ * the action that gets called when this `Observable` is unsubscribed
3647
+ * @return the source `Observable` modified so as to call this Action when appropriate
3648
+ * @see <a href="https://github.com/Netflix/RxJava/wiki/Observable-Utility-Operators#doonunsubscribe">RxJava wiki: doOnUnsubscribe</a>
3649
+ * @since 0.20
3650
+ */
3651
+ def doOnUnsubscribe (onUnsubscribe : => Unit ): Observable [T ] = {
3652
+ toScalaObservable[T ](asJavaObservable.doOnUnsubscribe(() => onUnsubscribe))
3653
+ }
3654
+
3611
3655
/**
3612
3656
* Given two Observables, mirror the one that first emits an item.
3613
3657
*
0 commit comments