throwIfEmpty.js 640 B

12345678910111213141516
  1. import { EmptyError } from '../util/EmptyError';
  2. import { operate } from '../util/lift';
  3. import { createOperatorSubscriber } from './OperatorSubscriber';
  4. export function throwIfEmpty(errorFactory = defaultErrorFactory) {
  5. return operate((source, subscriber) => {
  6. let hasValue = false;
  7. source.subscribe(createOperatorSubscriber(subscriber, (value) => {
  8. hasValue = true;
  9. subscriber.next(value);
  10. }, () => (hasValue ? subscriber.complete() : subscriber.error(errorFactory()))));
  11. });
  12. }
  13. function defaultErrorFactory() {
  14. return new EmptyError();
  15. }
  16. //# sourceMappingURL=throwIfEmpty.js.map