Implements the Observer interface and extends the Subscription class. While the Observer is the public API for consuming the values of an Observable, all Observers get converted to a Subscriber, in order to provide Subscription-like capabilities such as unsubscribe. Subscriber is a common type in RxJS, and crucial for implementing operators, but it is rarely used as a public API.

Subscriber

Type Parameters

  • T

Hierarchy (view full)

Implements

Constructors

  • Type Parameters

    • T

    Parameters

    Returns Subscriber<T>

    Deprecated

    Internal implementation detail, do not use directly. Will be made internal in v8. There is no reason to directly create an instance of Subscriber. This type is exported for typings reasons.

Properties

closed: boolean

A flag to indicate whether this Subscription has already been unsubscribed.

destination: Subscriber<any> | Observer<any>

Deprecated

Internal implementation detail, do not use directly. Will be made internal in v8.

isStopped: boolean

Deprecated

Internal implementation detail, do not use directly. Will be made internal in v8.

Nocollapse

Methods

  • Returns void

  • Parameters

    • err: any

    Returns void

  • Parameters

    • value: T

    Returns void

  • Adds a finalizer to this subscription, so that finalization will be unsubscribed/called when this subscription is unsubscribed. If this subscription is already #closed, because it has already been unsubscribed, then whatever finalizer is passed to it will automatically be executed (unless the finalizer itself is also a closed subscription).

    Closed Subscriptions cannot be added as finalizers to any subscription. Adding a closed subscription to a any subscription will result in no operation. (A noop).

    Adding a subscription to itself, or adding null or undefined will not perform any operation at all. (A noop).

    Subscription instances that are added to this instance will automatically remove themselves if they are unsubscribed. Functions and Unsubscribable objects that you wish to remove will need to be removed manually with #remove

    Parameters

    • teardown: TeardownLogic

      The finalization logic to add to this subscription.

    Returns void

  • The Observer callback to receive a valueless notification of type complete from the Observable. Notifies the Observer that the Observable has finished sending push-based notifications.

    Returns void

  • The Observer callback to receive notifications of type error from the Observable, with an attached Error. Notifies the Observer that the Observable has experienced an error condition.

    Parameters

    • Optional err: any

      The error exception.

    Returns void

  • The Observer callback to receive notifications of type next from the Observable, with a value. The Observable may call this method 0 or more times.

    Parameters

    • Optional value: T

      The next value.

    Returns void

  • Removes a finalizer from this subscription that was previously added with the #add method.

    Note that Subscription instances, when unsubscribed, will automatically remove themselves from every other Subscription they have been added to. This means that using the remove method is not a common thing and should be used thoughtfully.

    If you add the same finalizer instance of a function or an unsubscribable object to a Subscription instance more than once, you will need to call remove the same number of times to remove all instances.

    All finalizer instances are removed to free up memory upon unsubscription.

    Parameters

    Returns void

  • Disposes the resources held by the subscription. May, for instance, cancel an ongoing Observable execution or cancel any other type of work that started when the Subscription was created.

    Returns void

  • A static factory for a Subscriber, given a (potentially partial) definition of an Observer.

    Type Parameters

    • T

    Parameters

    • Optional next: ((x?) => void)

      The next callback of an Observer.

        • (x?): void
        • Parameters

          • Optional x: T

          Returns void

    • Optional error: ((e?) => void)

      The error callback of an Observer.

        • (e?): void
        • Parameters

          • Optional e: any

          Returns void

    • Optional complete: (() => void)

      The complete callback of an Observer.

        • (): void
        • Returns void

    Returns Subscriber<T>

    A Subscriber wrapping the (partially defined) Observer represented by the given arguments.

    Nocollapse

    Deprecated

    Do not use. Will be removed in v8. There is no replacement for this method, and there is no reason to be creating instances of Subscriber directly. If you have a specific use case, please file an issue.