function
deprecated
Creates an Observable that emits no items to the Observer and immediately emits a complete notification.
Deprecated in favor of using EMPTY constant, or scheduled
(e.g. scheduled([], scheduler)
)
empty(scheduler?: SchedulerLike)
scheduler | Optional. Default is A |
Just emits 'complete', and nothing else.
This static operator is useful for creating a simple Observable that only emits the complete notification. It can be used for composing with other Observables, such as in a mergeMap
.
import { empty } from 'rxjs'; import { startWith } from 'rxjs/operators'; const result = empty().pipe(startWith(7)); result.subscribe(x => console.log(x));
import { empty, interval, of } from 'rxjs'; import { mergeMap } from 'rxjs/operators'; const interval$ = interval(1000); const result = interval$.pipe( mergeMap(x => x % 2 === 1 ? of('a', 'b', 'c') : empty()), ); result.subscribe(x => console.log(x)); // Results in the following to the console: // x is equal to the count on the interval eg(0,1,2,3,...) // x will occur every 1000ms // if x % 2 is equal to 1 print abc // if x % 2 is not equal to 1 nothing will be output
© 2015–2018 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/function/empty