UNPKG

1.24 kBTypeScriptView Raw
1import { 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 */
38export declare function throwIfEmpty<T>(errorFactory?: () => any): MonoTypeOperatorFunction<T>;
39//# sourceMappingURL=throwIfEmpty.d.ts.map
\No newline at end of file