skip to content

defaultIfEmpty

 

Emits a given value if source observable has completed without ever emitting

1
2
3
4
5
6
7
8
9
10
11
12
const { rxObserver } = require('api/v0.3');
const { timer } = require('rxjs');
const { filter, defaultIfEmpty } = require('rxjs/operators');


const source$ = timer(100).pipe(filter(x => x !== 0));
const result$ = source$.pipe(defaultIfEmpty(42));

source$.subscribe(rxObserver('source$: empty, completing at 100ms'));
result$.subscribe(rxObserver('result$'));

0mssource$: empty, completing at 100msstartcompleteresult$startcomplete4242