wishthis/node_modules/rxjs/_esm5/internal/operators/throwIfEmpty.js
2022-05-29 11:24:36 +02:00

54 lines
1.8 KiB
JavaScript

/** PURE_IMPORTS_START tslib,_util_EmptyError,_Subscriber PURE_IMPORTS_END */
import * as tslib_1 from "tslib";
import { EmptyError } from '../util/EmptyError';
import { Subscriber } from '../Subscriber';
export function throwIfEmpty(errorFactory) {
if (errorFactory === void 0) {
errorFactory = defaultErrorFactory;
}
return function (source) {
return source.lift(new ThrowIfEmptyOperator(errorFactory));
};
}
var ThrowIfEmptyOperator = /*@__PURE__*/ (function () {
function ThrowIfEmptyOperator(errorFactory) {
this.errorFactory = errorFactory;
}
ThrowIfEmptyOperator.prototype.call = function (subscriber, source) {
return source.subscribe(new ThrowIfEmptySubscriber(subscriber, this.errorFactory));
};
return ThrowIfEmptyOperator;
}());
var ThrowIfEmptySubscriber = /*@__PURE__*/ (function (_super) {
tslib_1.__extends(ThrowIfEmptySubscriber, _super);
function ThrowIfEmptySubscriber(destination, errorFactory) {
var _this = _super.call(this, destination) || this;
_this.errorFactory = errorFactory;
_this.hasValue = false;
return _this;
}
ThrowIfEmptySubscriber.prototype._next = function (value) {
this.hasValue = true;
this.destination.next(value);
};
ThrowIfEmptySubscriber.prototype._complete = function () {
if (!this.hasValue) {
var err = void 0;
try {
err = this.errorFactory();
}
catch (e) {
err = e;
}
this.destination.error(err);
}
else {
return this.destination.complete();
}
};
return ThrowIfEmptySubscriber;
}(Subscriber));
function defaultErrorFactory() {
return new EmptyError();
}
//# sourceMappingURL=throwIfEmpty.js.map