@@ -48,6 +48,28 @@ import collection.JavaConversions._
48
48
* the observer
49
49
* @define subscribeObserverParamScheduler
50
50
* the [[rx.lang.scala.Scheduler ]] on which Observers subscribe to the Observable
51
+ *
52
+ * @define subscribeSubscriberMain
53
+ * Call this method to subscribe an [[Subscriber ]] for receiving items and notifications from the [[Observable ]].
54
+ *
55
+ * A typical implementation of `subscribe` does the following:
56
+ *
57
+ * It stores a reference to the Observer in a collection object, such as a `List[T]` object.
58
+ *
59
+ * It returns a reference to the [[rx.lang.scala.Subscription ]] interface. This enables [[Subscriber ]]s to
60
+ * unsubscribe, that is, to stop receiving items and notifications before the Observable stops
61
+ * sending them, which also invokes the Subscriber's [[rx.lang.scala.Observer.onCompleted onCompleted ]] method.
62
+ *
63
+ * An [[Observable ]] instance is responsible for accepting all subscriptions
64
+ * and notifying all [[Subscriber ]]s. Unless the documentation for a particular
65
+ * [[Observable ]] implementation indicates otherwise, [[Subscriber ]]s should make no
66
+ * assumptions about the order in which multiple [[Subscriber ]]s will receive their notifications.
67
+ *
68
+ * @define subscribeSubscriberParamObserver
69
+ * the [[Subscriber ]]
70
+ * @define subscribeSubscriberParamScheduler
71
+ * the [[rx.lang.scala.Scheduler ]] on which [[Subscriber ]]s subscribe to the Observable
72
+ *
51
73
* @define subscribeAllReturn
52
74
* a [[rx.lang.scala.Subscription ]] reference whose `unsubscribe` method can be called to stop receiving items
53
75
* before the Observable has finished sending them
@@ -125,6 +147,39 @@ trait Observable[+T]
125
147
*/
126
148
def apply (observer : Observer [T ]): Subscription = subscribe(observer)
127
149
150
+ /**
151
+ * $subscribeSubscriberMain
152
+ *
153
+ * @param subscriber $subscribeSubscriberParamObserver
154
+ * @param scheduler $subscribeSubscriberParamScheduler
155
+ * @return $subscribeAllReturn
156
+ */
157
+ def subscribe (subscriber : Subscriber [T ], scheduler : Scheduler ): Subscription = {
158
+ // Add the casting to avoid compile error "ambiguous reference to overloaded definition"
159
+ val thisJava = asJavaObservable.asInstanceOf [rx.Observable [T ]]
160
+ thisJava.subscribe(subscriber.asJavaSubscriber, scheduler)
161
+ }
162
+
163
+ /**
164
+ * $subscribeSubscriberMain
165
+ *
166
+ * @param subscriber $subscribeSubscriberParamObserver
167
+ * @return $subscribeAllReturn
168
+ */
169
+ def subscribe (subscriber : Subscriber [T ]): Subscription = {
170
+ // Add the casting to avoid compile error "ambiguous reference to overloaded definition"
171
+ val thisJava = asJavaObservable.asInstanceOf [rx.Observable [T ]]
172
+ thisJava.subscribe(subscriber.asJavaSubscriber)
173
+ }
174
+
175
+ /**
176
+ * $subscribeSubscriberMain
177
+ *
178
+ * @param subscriber $subscribeSubscriberParamObserver
179
+ * @return $subscribeAllReturn
180
+ */
181
+ def apply (subscriber : Subscriber [T ]): Subscription = subscribe(subscriber)
182
+
128
183
/**
129
184
* $subscribeCallbacksMainNoNotifications
130
185
*
@@ -2405,8 +2460,7 @@ trait Observable[+T]
2405
2460
2406
2461
/**
2407
2462
* Perform work in parallel by sharding an `Observable[T]` on a
2408
- * [[rx.lang.scala.concurrency.Schedulers.threadPoolForComputation computation ]]
2409
- * [[rx.lang.scala.Scheduler ]] and return an `Observable[R]` with the output.
2463
+ * [[rx.lang.scala.schedulers.ComputationScheduler ]] and return an `Observable[R]` with the output.
2410
2464
*
2411
2465
* @param f
2412
2466
* a function that applies Observable operators to `Observable[T]` in parallel and returns an `Observable[R]`
@@ -2636,12 +2690,10 @@ trait Observable[+T]
2636
2690
* those emitted by the source Observable
2637
2691
* @throws IndexOutOfBoundsException
2638
2692
* if index is greater than or equal to the number of items emitted by the source
2639
- * Observable
2640
- * @throws IndexOutOfBoundsException
2641
- * if index is less than 0
2693
+ * Observable, or index is less than 0
2642
2694
* @see `Observable.elementAt`
2643
- * @deprecated ("Use `elementAt`", "0.18.0")
2644
2695
*/
2696
+ @ deprecated(" Use `elementAt`" , " 0.18.0" )
2645
2697
def apply (index : Int ): Observable [T ] = elementAt(index)
2646
2698
2647
2699
/**
@@ -2656,9 +2708,7 @@ trait Observable[+T]
2656
2708
* those emitted by the source Observable
2657
2709
* @throws IndexOutOfBoundsException
2658
2710
* if index is greater than or equal to the number of items emitted by the source
2659
- * Observable
2660
- * @throws IndexOutOfBoundsException
2661
- * if index is less than 0
2711
+ * Observable, or index is less than 0
2662
2712
*/
2663
2713
def elementAt (index : Int ): Observable [T ] = {
2664
2714
toScalaObservable[T ](asJavaObservable.elementAt(index))
0 commit comments