Skip to content

Latest commit

 

History

History
15 lines (13 loc) · 440 Bytes

catchEmpty.md

File metadata and controls

15 lines (13 loc) · 440 Bytes

The catchEmpty Operator

This operator functions very similarly to catchComplete, only it will only catch a completed stream that has never emitted any values.

function catchEmpty<T, R>(fn: () => Observable<R>): OperatorFunction<T, T|R> {
  return s => defer(() => {
    let count = 0;
    return concat(
      s.pipe(tap(() => count++)),
      defer(() => count === 0? fn() : EMPTY)
    );
  });
}