ErrorObservable.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /** PURE_IMPORTS_START .._Observable PURE_IMPORTS_END */
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b)
  4. if (b.hasOwnProperty(p))
  5. d[p] = b[p];
  6. function __() { this.constructor = d; }
  7. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8. };
  9. import { Observable } from '../Observable';
  10. /**
  11. * We need this JSDoc comment for affecting ESDoc.
  12. * @extends {Ignored}
  13. * @hide true
  14. */
  15. export var ErrorObservable = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
  16. __extends(ErrorObservable, _super);
  17. function ErrorObservable(error, scheduler) {
  18. _super.call(this);
  19. this.error = error;
  20. this.scheduler = scheduler;
  21. }
  22. /**
  23. * Creates an Observable that emits no items to the Observer and immediately
  24. * emits an error notification.
  25. *
  26. * <span class="informal">Just emits 'error', and nothing else.
  27. * </span>
  28. *
  29. * <img src="./img/throw.png" width="100%">
  30. *
  31. * This static operator is useful for creating a simple Observable that only
  32. * emits the error notification. It can be used for composing with other
  33. * Observables, such as in a {@link mergeMap}.
  34. *
  35. * @example <caption>Emit the number 7, then emit an error.</caption>
  36. * var result = Rx.Observable.throw(new Error('oops!')).startWith(7);
  37. * result.subscribe(x => console.log(x), e => console.error(e));
  38. *
  39. * @example <caption>Map and flatten numbers to the sequence 'a', 'b', 'c', but throw an error for 13</caption>
  40. * var interval = Rx.Observable.interval(1000);
  41. * var result = interval.mergeMap(x =>
  42. * x === 13 ?
  43. * Rx.Observable.throw('Thirteens are bad') :
  44. * Rx.Observable.of('a', 'b', 'c')
  45. * );
  46. * result.subscribe(x => console.log(x), e => console.error(e));
  47. *
  48. * @see {@link create}
  49. * @see {@link empty}
  50. * @see {@link never}
  51. * @see {@link of}
  52. *
  53. * @param {any} error The particular Error to pass to the error notification.
  54. * @param {Scheduler} [scheduler] A {@link IScheduler} to use for scheduling
  55. * the emission of the error notification.
  56. * @return {Observable} An error Observable: emits only the error notification
  57. * using the given error argument.
  58. * @static true
  59. * @name throw
  60. * @owner Observable
  61. */
  62. ErrorObservable.create = function (error, scheduler) {
  63. return new ErrorObservable(error, scheduler);
  64. };
  65. ErrorObservable.dispatch = function (arg) {
  66. var error = arg.error, subscriber = arg.subscriber;
  67. subscriber.error(error);
  68. };
  69. /** @deprecated internal use only */ ErrorObservable.prototype._subscribe = function (subscriber) {
  70. var error = this.error;
  71. var scheduler = this.scheduler;
  72. subscriber.syncErrorThrowable = true;
  73. if (scheduler) {
  74. return scheduler.schedule(ErrorObservable.dispatch, 0, {
  75. error: error, subscriber: subscriber
  76. });
  77. }
  78. else {
  79. subscriber.error(error);
  80. }
  81. };
  82. return ErrorObservable;
  83. }(Observable));
  84. //# sourceMappingURL=ErrorObservable.js.map