rxjs / 7.5.5 / api / index / const / empty.html /

EMPTY

const stable

A simple Observable that emits no items to the Observer and immediately emits a complete notification.

const EMPTY: Observable<never>;

Description

Just emits 'complete', and nothing else.

empty marble diagram

A simple Observable that only emits the complete notification. It can be used for composing with other Observables, such as in a mergeMap.

Examples

Log complete notification

import { EMPTY } from 'rxjs';

EMPTY.subscribe({
  next: () => console.log('Next'),
  complete: () => console.log('Complete!')
});

// Outputs
// Complete!

Emit the number 7, then complete

import { EMPTY, startWith } from 'rxjs';

const result = EMPTY.pipe(startWith(7));
result.subscribe(x => console.log(x));

// Outputs
// 7

Map and flatten only odd numbers to the sequence 'a', 'b', 'c'

import { interval, mergeMap, of, EMPTY } from 'rxjs';

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, e.g. (0, 1, 2, 3, ...)
// x will occur every 1000ms
// if x % 2 is equal to 1, print a, b, c (each on its own)
// if x % 2 is not equal to 1, nothing will be output

See Also

© 2015–2022 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/const/EMPTY