work.suroh.tk/node_modules/rxjs/_esm5/observable/ErrorObservable.js

85 lines
3.1 KiB
JavaScript
Raw Normal View History

2019-12-02 12:22:45 +00:00
/** PURE_IMPORTS_START .._Observable PURE_IMPORTS_END */
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b)
if (b.hasOwnProperty(p))
d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
import { Observable } from '../Observable';
/**
* We need this JSDoc comment for affecting ESDoc.
* @extends {Ignored}
* @hide true
*/
export var ErrorObservable = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
__extends(ErrorObservable, _super);
function ErrorObservable(error, scheduler) {
_super.call(this);
this.error = error;
this.scheduler = scheduler;
}
/**
* Creates an Observable that emits no items to the Observer and immediately
* emits an error notification.
*
* <span class="informal">Just emits 'error', and nothing else.
* </span>
*
* <img src="./img/throw.png" width="100%">
*
* This static operator is useful for creating a simple Observable that only
* emits the error notification. It can be used for composing with other
* Observables, such as in a {@link mergeMap}.
*
* @example <caption>Emit the number 7, then emit an error.</caption>
* var result = Rx.Observable.throw(new Error('oops!')).startWith(7);
* result.subscribe(x => console.log(x), e => console.error(e));
*
* @example <caption>Map and flatten numbers to the sequence 'a', 'b', 'c', but throw an error for 13</caption>
* var interval = Rx.Observable.interval(1000);
* var result = interval.mergeMap(x =>
* x === 13 ?
* Rx.Observable.throw('Thirteens are bad') :
* Rx.Observable.of('a', 'b', 'c')
* );
* result.subscribe(x => console.log(x), e => console.error(e));
*
* @see {@link create}
* @see {@link empty}
* @see {@link never}
* @see {@link of}
*
* @param {any} error The particular Error to pass to the error notification.
* @param {Scheduler} [scheduler] A {@link IScheduler} to use for scheduling
* the emission of the error notification.
* @return {Observable} An error Observable: emits only the error notification
* using the given error argument.
* @static true
* @name throw
* @owner Observable
*/
ErrorObservable.create = function (error, scheduler) {
return new ErrorObservable(error, scheduler);
};
ErrorObservable.dispatch = function (arg) {
var error = arg.error, subscriber = arg.subscriber;
subscriber.error(error);
};
/** @deprecated internal use only */ ErrorObservable.prototype._subscribe = function (subscriber) {
var error = this.error;
var scheduler = this.scheduler;
subscriber.syncErrorThrowable = true;
if (scheduler) {
return scheduler.schedule(ErrorObservable.dispatch, 0, {
error: error, subscriber: subscriber
});
}
else {
subscriber.error(error);
}
};
return ErrorObservable;
}(Observable));
//# sourceMappingURL=ErrorObservable.js.map