File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
language-adaptors/rxjava-scala/src
examples/scala/rx/lang/scala/examples Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -560,6 +560,26 @@ class RxScalaDemo extends JUnitSuite {
560
560
obs.toBlockingObservable.toIterable.last
561
561
}
562
562
563
+ @ Test def doOnTerminateExample (): Unit = {
564
+ val o = List (" red" , " green" , " blue" ).toObservable.doOnTerminate(() => println(" terminate" ))
565
+ o.subscribe(v => println(v), e => e.printStackTrace, () => println(" onCompleted" ))
566
+ // red
567
+ // green
568
+ // blud
569
+ // terminate
570
+ // onCompleted
571
+ }
572
+
573
+ @ Test def finallyDoExample (): Unit = {
574
+ val o = List (" red" , " green" , " blue" ).toObservable.finallyDo(() => println(" finally" ))
575
+ o.subscribe(v => println(v), e => e.printStackTrace, () => println(" onCompleted" ))
576
+ // red
577
+ // green
578
+ // blud
579
+ // onCompleted
580
+ // finally
581
+ }
582
+
563
583
@ Test def timeoutExample (): Unit = {
564
584
val other = List (100L , 200L , 300L ).toObservable
565
585
val result = Observable .interval(100 millis).timeout(50 millis, other).toBlockingObservable.toList
Original file line number Diff line number Diff line change @@ -2461,6 +2461,22 @@ trait Observable[+T]
2461
2461
toScalaObservable[T ](asJavaObservable.doOnEach(Observer (onNext, onError,onCompleted)))
2462
2462
}
2463
2463
2464
+ /**
2465
+ * Modifies an Observable so that it invokes an action when it calls `onCompleted` or `onError`.
2466
+ * <p>
2467
+ * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/doOnTerminate.png">
2468
+ * <p>
2469
+ * This differs from `finallyDo` in that this happens BEFORE onCompleted/onError are emitted.
2470
+ *
2471
+ * @param onTerminate the action to invoke when the source Observable calls `onCompleted` or `onError`
2472
+ * @return the source Observable with the side-effecting behavior applied
2473
+ * @see <a href="https://github.com/Netflix/RxJava/wiki/Observable-Utility-Operators#wiki-doonterminate">RxJava Wiki: doOnTerminate()</a>
2474
+ * @see <a href="http://msdn.microsoft.com/en-us/library/hh229804.aspx">MSDN: Observable.Do</a>
2475
+ */
2476
+ def doOnTerminate (onTerminate : () => Unit ): Observable [T ] = {
2477
+ toScalaObservable[T ](asJavaObservable.doOnTerminate(onTerminate))
2478
+ }
2479
+
2464
2480
/**
2465
2481
* Given two Observables, mirror the one that first emits an item.
2466
2482
*
You can’t perform that action at this time.
0 commit comments