hugoWebsite/node_modules/rxjs/dist/esm/internal/operators/throwIfEmpty.js

16 lines
640 B
JavaScript
Raw Normal View History

2022-10-29 00:20:35 +02:00
import { EmptyError } from '../util/EmptyError';
import { operate } from '../util/lift';
import { createOperatorSubscriber } from './OperatorSubscriber';
export function throwIfEmpty(errorFactory = defaultErrorFactory) {
return operate((source, subscriber) => {
let hasValue = false;
source.subscribe(createOperatorSubscriber(subscriber, (value) => {
hasValue = true;
subscriber.next(value);
}, () => (hasValue ? subscriber.complete() : subscriber.error(errorFactory()))));
});
}
function defaultErrorFactory() {
return new EmptyError();
}
//# sourceMappingURL=throwIfEmpty.js.map