Options
All
  • Public
  • Public/Protected
  • All
Menu

A representation of any set of values over any amount of time. This is the most basic building block of RxJS.

Type Parameters

  • T

Hierarchy

  • Observable

Implements

Index

Constructors

  • Type Parameters

    • T

    Parameters

    • Optional subscribe: ((this: Observable<T>, subscriber: Subscriber<T>) => TeardownLogic)

      the function that is called when the Observable is initially subscribed to. This function is given a Subscriber, to which new values can be nexted, or an error method can be called to raise an error, or complete can be called to notify of a successful completion.

    Returns Observable<T>

Properties

operator: undefined | Operator<any, T>
deprecated

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

source: undefined | Observable<any>
deprecated

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

create: ((...args: any[]) => any)

Type declaration

    • (...args: any[]): any
    • Creates a new Observable by calling the Observable constructor

      owner

      Observable

      method

      create

      nocollapse
      deprecated

      Use new Observable() instead. Will be removed in v8.

      Parameters

      • Rest ...args: any[]

      Returns any

      a new observable

Methods

  • Used as a NON-CANCELLABLE means of subscribing to an observable, for use with APIs that expect promises, like async/await. You cannot unsubscribe from this.

    WARNING: Only use this with observables you know will complete. If the source observable does not complete, you will end up with a promise that is hung up, and potentially all of the state of an async function hanging out in memory. To avoid this situation, look into adding something like {@link timeout}, {@link take}, {@link takeWhile}, or {@link takeUntil} amongst others.

    Example

    import { interval, take } from 'rxjs';

    const source$ = interval(1000).pipe(take(4));

    async function getTotal() {
    let total = 0;

    await source$.forEach(value => {
    total += value;
    console.log('observable -> ' + value);
    });

    return total;
    }

    getTotal().then(
    total => console.log('Total: ' + total)
    );

    // Expected:
    // 'observable -> 0'
    // 'observable -> 1'
    // 'observable -> 2'
    // 'observable -> 3'
    // 'Total: 6'

    Parameters

    • next: ((value: T) => void)

      a handler for each value emitted by the observable

        • (value: T): void
        • Parameters

          • value: T

          Returns void

    Returns internal.Promise<void>

    a promise that either resolves on observable completion or rejects with the handled error

  • deprecated

    Passing a Promise constructor will no longer be available in upcoming versions of RxJS. This is because it adds weight to the library, for very little benefit. If you need this functionality, it is recommended that you either polyfill Promise, or you create an adapter to convert the returned native promise to whatever promise implementation you wanted. Will be removed in v8.

    Parameters

    • next: ((value: T) => void)

      a handler for each value emitted by the observable

        • (value: T): void
        • Parameters

          • value: T

          Returns void

    • promiseCtor: PromiseConstructorLike

      a constructor function used to instantiate the Promise

    Returns internal.Promise<void>

    a promise that either resolves on observable completion or rejects with the handled error

  • Creates a new Observable, with this Observable instance as the source, and the passed operator defined as the new observable's operator.

    method

    lift

    deprecated

    Internal implementation detail, do not use directly. Will be made internal in v8. If you have implemented an operator using lift, it is recommended that you create an operator by simply returning new Observable() directly. See "Creating new operators from scratch" section here: https://rxjs.dev/guide/operators

    Type Parameters

    • R

    Parameters

    • Optional operator: Operator<T, R>

      the operator defining the operation to take on the observable

    Returns Observable<R>

    a new observable with the Operator applied

  • subscribe(observerOrNext?: Partial<Observer<T>> | ((value: T) => void)): Subscription
  • subscribe(next?: null | ((value: T) => void), error?: null | ((error: any) => void), complete?: null | (() => void)): Subscription
  • deprecated

    Instead of passing separate callback arguments, use an observer argument. Signatures taking separate callback arguments will be removed in v8. Details: https://rxjs.dev/deprecations/subscribe-arguments

    Parameters

    • Optional observerOrNext: Partial<Observer<T>> | ((value: T) => void)

    Returns Subscription

  • deprecated

    Instead of passing separate callback arguments, use an observer argument. Signatures taking separate callback arguments will be removed in v8. Details: https://rxjs.dev/deprecations/subscribe-arguments

    Parameters

    • Optional next: null | ((value: T) => void)
    • Optional error: null | ((error: any) => void)
    • Optional complete: null | (() => void)

    Returns Subscription

Generated using TypeDoc