abstract class Subscriber[-T] extends Observer[T] with Subscription
An extension of the Observer trait which adds subscription handling
(unsubscribe, isUnsubscribed, and add methods) and backpressure handling
(onStart and request methods).
After a Subscriber calls an Observable's subscribe method, the
Observable calls the Subscriber's onNext method to emit items. A well-behaved
Observable will call a Subscriber's onCompleted method exactly once or the Subscriber's
onError method exactly once.
Similarly to the RxJava Subscriber, this class has two constructors:
The first constructor takes as argument the child Subscriber from further down the pipeline and is usually only needed together with lift:
myObservable.lift((subscriber: Subscriber[T]) => new Subscriber[T](subscriber) { override def onStart(): Unit = ... override def onNext(n: T): Unit = ... override def onError(e: Throwable): Unit = ... override def onCompleted(): Unit = ... })
The second constructor takes no arguments and is typically used with the subscribe method:
myObservable.subscribe(new Subscriber[T] { override def onStart(): Unit = ... override def onNext(n: T): Unit = ... override def onError(e: Throwable): Unit = ... override def onCompleted(): Unit = ... })
Notice that these two constructors are not (as usually in Scala) in the companion object,
because if they were, we couldn't create anonymous classes implementing
onStart/onNext/onError/onCompleted as in the examples above.
However, there are more constructors in the companion object, which allow you to construct
Subscribers from given onNext/onError/onCompleted lambdas.
- Self Type
- Subscriber[T]
- Alphabetic
- By Inheritance
- Subscriber
- Subscription
- Observer
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new Subscriber()
- new Subscriber(subscriber: Subscriber[_])
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
add(u: ⇒ Unit): Unit
Create a Subscription using
uand add it to this Subscriber's list of Subscriptions if this list is not marked as unsubscribed.Create a Subscription using
uand add it to this Subscriber's list of Subscriptions if this list is not marked as unsubscribed. If the list **is** marked as unsubscribed, it will callu.- u
callback to run when unsubscribed
-
final
def
add(s: Subscription): Unit
Add a Subscription to this Subscriber's list of Subscriptions if this list is not marked as unsubscribed.
Add a Subscription to this Subscriber's list of Subscriptions if this list is not marked as unsubscribed. If the list **is** marked as unsubscribed, it will unsubscribe the new Subscription as well.
- s
the Subscription to add
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
isUnsubscribed: Boolean
Indicates whether this Subscriber has unsubscribed from its list of Subscriptions.
Indicates whether this Subscriber has unsubscribed from its list of Subscriptions.
- returns
trueif this Subscriber has unsubscribed from its Subscriptions,falseotherwise
- Definition Classes
- Subscriber → Subscription
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
-
def
onCompleted(): Unit
Notifies the Observer that the rx.lang.scala.Observable has finished sending push-based notifications.
Notifies the Observer that the rx.lang.scala.Observable has finished sending push-based notifications.
The rx.lang.scala.Observable will not call this method if it calls
onError.- Definition Classes
- Observer
-
def
onError(error: Throwable): Unit
Notifies the Observer that the rx.lang.scala.Observable has experienced an error condition.
Notifies the Observer that the rx.lang.scala.Observable has experienced an error condition.
If the rx.lang.scala.Observable calls this method, it will not thereafter call
onNextoronCompleted.- Definition Classes
- Observer
-
def
onNext(value: T): Unit
Provides the Observer with new data.
Provides the Observer with new data.
The rx.lang.scala.Observable calls this closure 0 or more times.
The rx.lang.scala.Observable will not call this method again after it calls either
onCompletedoronError.- Definition Classes
- Observer
-
def
onStart(): Unit
This method is invoked when the Subscriber and Observable have been connected but the Observable has not yet begun to emit items or send notifications to the Subscriber.
This method is invoked when the Subscriber and Observable have been connected but the Observable has not yet begun to emit items or send notifications to the Subscriber. Override this method to add any useful initialization to your subscription, for instance to initiate backpressure.
Observable.just(1, 2, 3).subscribe(new Subscriber[Int]() { override def onStart(): Unit = request(1) override def onNext(v: Int): Unit = { println(v) request(1) } override def onError(e: Throwable): Unit = e.printStackTrace() override def onCompleted(): Unit = {} })
-
final
def
request(n: Long): Unit
Request a certain maximum number of emitted items from the Observable this Subscriber is subscribed to.
Request a certain maximum number of emitted items from the Observable this Subscriber is subscribed to. This is a way of requesting backpressure. To disable backpressure, pass
Long.MaxValueto this method.- n
the maximum number of items you want the Observable to emit to the Subscriber at this time, or
Long.MaxValueif you want the Observable to emit items at its own pace
- Attributes
- protected[this]
- def setProducer(producer: (Long) ⇒ Unit): Unit
- def setProducer(producer: Producer): Unit
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
unsubscribe(): Unit
Unsubscribe all Subscriptions added to this Subscriber's .
Unsubscribe all Subscriptions added to this Subscriber's .
- Definition Classes
- Subscriber → Subscription
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )