rx.lang.scala

Subscriber

Related Docs: object Subscriber | package scala

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]
Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Subscriber
  2. Subscription
  3. Observer
  4. AnyRef
  5. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Subscriber()

  2. new Subscriber(subscriber: Subscriber[_])

Value Members

  1. final def !=(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  4. final def add(u: ⇒ Unit): Unit

    Create a Subscription using u and add it to this Subscriber's list of Subscriptions if this list is not marked as unsubscribed.

    Create a Subscription using u and 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 call u.

    u

    callback to run when unsubscribed

  5. 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

  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  9. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  10. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  11. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  12. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  13. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  14. 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

    true if this Subscriber has unsubscribed from its Subscriptions, false otherwise

    Definition Classes
    SubscriberSubscription
  15. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  16. final def notify(): Unit

    Definition Classes
    AnyRef
  17. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  18. 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
  19. 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 onNext or onCompleted.

    Definition Classes
    Observer
  20. 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 onCompleted or onError.

    Definition Classes
    Observer
  21. 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 = {}
    })
  22. 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.MaxValue to this method.

    n

    the maximum number of items you want the Observable to emit to the Subscriber at this time, or Long.MaxValue if you want the Observable to emit items at its own pace

    Attributes
    protected[this]
  23. def setProducer(producer: (Long) ⇒ Unit): Unit

  24. def setProducer(producer: Producer): Unit

  25. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  26. def toString(): String

    Definition Classes
    AnyRef → Any
  27. final def unsubscribe(): Unit

    Unsubscribe all Subscriptions added to this Subscriber's .

    Unsubscribe all Subscriptions added to this Subscriber's .

    Definition Classes
    SubscriberSubscription
  28. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  29. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Subscription

Inherited from Observer[T]

Inherited from AnyRef

Inherited from Any

Ungrouped