Skip to content

Commit f20a8eb

Browse files
make Subscription an implicit value class
1 parent 450be12 commit f20a8eb

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/ImplicitFunctionConversions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ object ImplicitFunctionConversions {
2929

3030
implicit def scalaFunction1ToOnSubscribeFunc[T](f: rx.lang.scala.Observer[T] => Subscription) =
3131
new rx.Observable.OnSubscribeFunc[T] {
32-
def onSubscribe(obs: Observer[_ >: T]): Subscription = {
33-
f(obs)
32+
def onSubscribe(obs: Observer[_ >: T]): rx.Subscription = {
33+
f(obs).asJava
3434
}
3535
}
3636

language-adaptors/rxjava-scala/src/main/scala/rx/lang/scala/package.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,20 @@ package object scala {
3535

3636
type Observer[-T] = rx.Observer[_ >: T]
3737
type Scheduler = rx.Scheduler
38-
type Subscription = rx.Subscription
3938

39+
/**
40+
* Subscriptions are returned from all Observable.subscribe methods to allow unsubscribing.
41+
*
42+
* This interface is the RxJava equivalent of IDisposable in Microsoft's Rx implementation.
43+
*/
44+
implicit class Subscription(val asJava: rx.Subscription) extends AnyVal {
45+
/**
46+
* Call this to stop receiving notifications on the Observer that was registered when
47+
* this Subscription was received.
48+
*/
49+
def unsubscribe(): Unit = asJava.unsubscribe()
50+
}
51+
4052
}
4153

4254
/*

0 commit comments

Comments
 (0)