Options
All
  • Public
  • Public/Protected
  • All
Menu

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.

Type parameters

  • T

Hierarchy

Implements

Index

Constructors

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

    Type parameters

    • T

    Parameters

    Returns Subscriber<T>

Properties

closed: boolean

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

nocollapse

Methods

  • Adds a finalizer to this subscription, so that finalization will be unsubscribed/called when this subscription is unsubscribed. If this subscription is already {@link #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 {@link #remove}

    Parameters

    • teardown: TeardownLogic

      The finalization logic to add to this subscription.

    Returns void

  • complete(): 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

  • error(err?: any): 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

    Returns void

  • next(value?: T): 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

    Returns void

  • Removes a finalizer from this subscription that was previously added with the {@link #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

  • unsubscribe(): 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

  • create<T>(next?: (x?: T) => void, error?: (e?: any) => void, complete?: () => void): Subscriber<T>
  • A static factory for a Subscriber, given a (potentially partial) definition of an Observer.

    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.

    Type parameters

    • T

    Parameters

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

      The next callback of an Observer.

        • (x?: T): void
        • Parameters

          • Optional x: T

          Returns void

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

      The error callback of an Observer.

        • (e?: any): 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.