File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed
language-adaptors/rxjava-scala/src
examples/scala/rx/lang/scala/examples Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -1048,4 +1048,16 @@ class RxScalaDemo extends JUnitSuite {
1048
1048
val o = hot.publishLast(co => co ++ co) // "++" subscribes "co" twice
1049
1049
o.subscribe(n => println(s " subscriber gets $n" ))
1050
1050
}
1051
+
1052
+ @ Test def unsubscribeOnExample () {
1053
+ val o = Observable [String ] {
1054
+ subscriber =>
1055
+ subscriber.add(Subscription {
1056
+ println(" unsubscribe on " + Thread .currentThread().getName())
1057
+ })
1058
+ subscriber.onNext(" RxScala" )
1059
+ subscriber.onCompleted()
1060
+ }
1061
+ o.unsubscribeOn(NewThreadScheduler ()).subscribe(println(_))
1062
+ }
1051
1063
}
Original file line number Diff line number Diff line change @@ -949,6 +949,17 @@ trait Observable[+T]
949
949
toScalaObservable[T ](asJavaObservable.subscribeOn(scheduler))
950
950
}
951
951
952
+ /**
953
+ * Asynchronously unsubscribes on the specified [[Scheduler ]].
954
+ *
955
+ * @param scheduler the [[Scheduler ]] to perform subscription and unsubscription actions on
956
+ * @return the source Observable modified so that its unsubscriptions happen on the specified [[Scheduler ]]
957
+ * @since 0.17
958
+ */
959
+ def unsubscribeOn (scheduler : Scheduler ): Observable [T ] = {
960
+ toScalaObservable[T ](asJavaObservable.unsubscribeOn(scheduler))
961
+ }
962
+
952
963
/**
953
964
* Asynchronously notify [[rx.lang.scala.Observer ]]s on the specified [[rx.lang.scala.Scheduler ]].
954
965
*
You can’t perform that action at this time.
0 commit comments