Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

retryWhen.js 3.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. }
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var Subject_1 = require("../Subject");
  17. var tryCatch_1 = require("../util/tryCatch");
  18. var errorObject_1 = require("../util/errorObject");
  19. var OuterSubscriber_1 = require("../OuterSubscriber");
  20. var subscribeToResult_1 = require("../util/subscribeToResult");
  21. function retryWhen(notifier) {
  22. return function (source) { return source.lift(new RetryWhenOperator(notifier, source)); };
  23. }
  24. exports.retryWhen = retryWhen;
  25. var RetryWhenOperator = (function () {
  26. function RetryWhenOperator(notifier, source) {
  27. this.notifier = notifier;
  28. this.source = source;
  29. }
  30. RetryWhenOperator.prototype.call = function (subscriber, source) {
  31. return source.subscribe(new RetryWhenSubscriber(subscriber, this.notifier, this.source));
  32. };
  33. return RetryWhenOperator;
  34. }());
  35. var RetryWhenSubscriber = (function (_super) {
  36. __extends(RetryWhenSubscriber, _super);
  37. function RetryWhenSubscriber(destination, notifier, source) {
  38. var _this = _super.call(this, destination) || this;
  39. _this.notifier = notifier;
  40. _this.source = source;
  41. return _this;
  42. }
  43. RetryWhenSubscriber.prototype.error = function (err) {
  44. if (!this.isStopped) {
  45. var errors = this.errors;
  46. var retries = this.retries;
  47. var retriesSubscription = this.retriesSubscription;
  48. if (!retries) {
  49. errors = new Subject_1.Subject();
  50. retries = tryCatch_1.tryCatch(this.notifier)(errors);
  51. if (retries === errorObject_1.errorObject) {
  52. return _super.prototype.error.call(this, errorObject_1.errorObject.e);
  53. }
  54. retriesSubscription = subscribeToResult_1.subscribeToResult(this, retries);
  55. }
  56. else {
  57. this.errors = null;
  58. this.retriesSubscription = null;
  59. }
  60. this._unsubscribeAndRecycle();
  61. this.errors = errors;
  62. this.retries = retries;
  63. this.retriesSubscription = retriesSubscription;
  64. errors.next(err);
  65. }
  66. };
  67. RetryWhenSubscriber.prototype._unsubscribe = function () {
  68. var _a = this, errors = _a.errors, retriesSubscription = _a.retriesSubscription;
  69. if (errors) {
  70. errors.unsubscribe();
  71. this.errors = null;
  72. }
  73. if (retriesSubscription) {
  74. retriesSubscription.unsubscribe();
  75. this.retriesSubscription = null;
  76. }
  77. this.retries = null;
  78. };
  79. RetryWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  80. var _unsubscribe = this._unsubscribe;
  81. this._unsubscribe = null;
  82. this._unsubscribeAndRecycle();
  83. this._unsubscribe = _unsubscribe;
  84. this.source.subscribe(this);
  85. };
  86. return RetryWhenSubscriber;
  87. }(OuterSubscriber_1.OuterSubscriber));
  88. //# sourceMappingURL=retryWhen.js.map