Search code examples
rxjsrxjs5

Any need to call unsubscribe for RxJS first()


In the following code:-

RxJS.Observable.of(1,2).first().subscribe((x) => console.log(x););

is it necessary to unsubscribe given the operator first()?


Solution

  • No. It unsubscribes automatically after calling first(). The current syntax is observable.pipe(first()).subscribe(func); for RxJS 6.

    The documentation states:

    If called with no arguments, first emits the first value of the source Observable, then completes.