67190aafd2197ea97d480fc85d48df21f7340c2af6bbb1331d4fdeea87c1ba507085e31aa7ea0816ea4cfdcfbeb29bb4c6be99bb4c3ac09b48ae463303d187 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { MonoTypeOperatorFunction } from '../types';
  2. /**
  3. * If the source observable completes without emitting a value, it will emit
  4. * an error. The error will be created at that time by the optional
  5. * `errorFactory` argument, otherwise, the error will be {@link EmptyError}.
  6. *
  7. * ![](throwIfEmpty.png)
  8. *
  9. * ## Example
  10. *
  11. * Throw an error if the document wasn't clicked within 1 second
  12. *
  13. * ```ts
  14. * import { fromEvent, takeUntil, timer, throwIfEmpty } from 'rxjs';
  15. *
  16. * const click$ = fromEvent(document, 'click');
  17. *
  18. * click$.pipe(
  19. * takeUntil(timer(1000)),
  20. * throwIfEmpty(() => new Error('The document was not clicked within 1 second'))
  21. * )
  22. * .subscribe({
  23. * next() {
  24. * console.log('The document was clicked');
  25. * },
  26. * error(err) {
  27. * console.error(err.message);
  28. * }
  29. * });
  30. * ```
  31. *
  32. * @param errorFactory A factory function called to produce the
  33. * error to be thrown when the source observable completes without emitting a
  34. * value.
  35. * @return A function that returns an Observable that throws an error if the
  36. * source Observable completed without emitting.
  37. */
  38. export declare function throwIfEmpty<T>(errorFactory?: () => any): MonoTypeOperatorFunction<T>;
  39. //# sourceMappingURL=throwIfEmpty.d.ts.map