Subscriber

class stable

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.

class Subscriber<T> extends Subscription implements Observer {
  static create<T>(next?: (x?: T) => void, error?: (e?: any) => void, complete?: () => void): Subscriber<T>
  constructor(destination?: Subscriber<any> | Observer<any>)
  protected isStopped: boolean
  protected destination: Subscriber<any> | Observer<any>
  next(value?: T): void
  error(err?: any): void
  complete(): void
  unsubscribe(): void
  protected _next(value: T): void
  protected _error(err: any): void
  protected _complete(): void

  // inherited from index/Subscription
  static EMPTY: (() => {...})
  constructor(initialTeardown?: () => void)
  closed: false
  unsubscribe(): void
  add(teardown: TeardownLogic): void
  remove(teardown: Subscription | Unsubscribable | (() => void)): void
}

Static Methods

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

static create<T>(next?: (x?: T) => void, error?: (e?: any) => void, complete?: () => void): Subscriber<T>

Deprecation Notes

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.

Parameters

next

Optional. Default is undefined.

The next callback of an Observer.

error

Optional. Default is undefined.

The error callback of an Observer.

complete

Optional. Default is undefined.

The complete callback of an Observer.

Returns

Subscriber<T>: A Subscriber wrapping the (partially defined) Observer represented by the given arguments.

Constructor

constructor(destination?: Subscriber<any> | Observer<any>)

Deprecation Notes

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.

Parameters

destination

Optional. Default is undefined.

Type: Subscriber | Observer.

Properties

Property Type Description
isStopped boolean
destination Subscriber<any> | Observer<any>

Methods

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

value

Optional. Default is undefined.

The next value.

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

err

Optional. Default is undefined.

The error exception.

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.

Parameters

There are no parameters.

Returns

void:

unsubscribe(): void

Parameters

There are no parameters.

Returns

void

protected _next(value: T): void

Parameters

value

Type: T.

Returns

void

protected _error(err: any): void

Parameters

err

Type: any.

Returns

void

protected _complete(): void

Parameters

There are no parameters.

Returns

void

© 2015–2021 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/index/class/Subscriber