1 import { Observable } from '../Observable';
2 import { SchedulerLike } from '../types';
5 * The same Observable instance returned by any call to {@link empty} without a
6 * `scheduler`. It is preferrable to use this over `empty()`.
8 export const EMPTY = new Observable<never>(subscriber => subscriber.complete());
11 * Creates an Observable that emits no items to the Observer and immediately
12 * emits a complete notification.
14 * <span class="informal">Just emits 'complete', and nothing else.
19 * This static operator is useful for creating a simple Observable that only
20 * emits the complete notification. It can be used for composing with other
21 * Observables, such as in a {@link mergeMap}.
24 * ### Emit the number 7, then complete
26 * import { empty } from 'rxjs';
27 * import { startWith } from 'rxjs/operators';
29 * const result = empty().pipe(startWith(7));
30 * result.subscribe(x => console.log(x));
33 * ### Map and flatten only odd numbers to the sequence 'a', 'b', 'c'
35 * import { empty, interval, of } from 'rxjs';
36 * import { mergeMap } from 'rxjs/operators';
38 * const interval$ = interval(1000);
39 * const result = interval$.pipe(
40 * mergeMap(x => x % 2 === 1 ? of('a', 'b', 'c') : empty()),
42 * result.subscribe(x => console.log(x));
44 * // Results in the following to the console:
45 * // x is equal to the count on the interval eg(0,1,2,3,...)
46 * // x will occur every 1000ms
47 * // if x % 2 is equal to 1 print abc
48 * // if x % 2 is not equal to 1 nothing will be output
51 * @see {@link Observable}
54 * @see {@link throwError}
56 * @param scheduler A {@link SchedulerLike} to use for scheduling
57 * the emission of the complete notification.
58 * @return An "empty" Observable: emits only the complete
60 * @deprecated Deprecated in favor of using {@link EMPTY} constant, or {@link scheduled} (e.g. `scheduled([], scheduler)`)
62 export function empty(scheduler?: SchedulerLike) {
63 return scheduler ? emptyScheduled(scheduler) : EMPTY;
66 function emptyScheduled(scheduler: SchedulerLike) {
67 return new Observable<never>(subscriber => scheduler.schedule(() => subscriber.complete()));