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.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 OuterSubscriber_1 = require("../OuterSubscriber");
  18. var subscribeToResult_1 = require("../util/subscribeToResult");
  19. function retryWhen(notifier) {
  20. return function (source) { return source.lift(new RetryWhenOperator(notifier, source)); };
  21. }
  22. exports.retryWhen = retryWhen;
  23. var RetryWhenOperator = (function () {
  24. function RetryWhenOperator(notifier, source) {
  25. this.notifier = notifier;
  26. this.source = source;
  27. }
  28. RetryWhenOperator.prototype.call = function (subscriber, source) {
  29. return source.subscribe(new RetryWhenSubscriber(subscriber, this.notifier, this.source));
  30. };
  31. return RetryWhenOperator;
  32. }());
  33. var RetryWhenSubscriber = (function (_super) {
  34. __extends(RetryWhenSubscriber, _super);
  35. function RetryWhenSubscriber(destination, notifier, source) {
  36. var _this = _super.call(this, destination) || this;
  37. _this.notifier = notifier;
  38. _this.source = source;
  39. return _this;
  40. }
  41. RetryWhenSubscriber.prototype.error = function (err) {
  42. if (!this.isStopped) {
  43. var errors = this.errors;
  44. var retries = this.retries;
  45. var retriesSubscription = this.retriesSubscription;
  46. if (!retries) {
  47. errors = new Subject_1.Subject();
  48. try {
  49. var notifier = this.notifier;
  50. retries = notifier(errors);
  51. }
  52. catch (e) {
  53. return _super.prototype.error.call(this, e);
  54. }
  55. retriesSubscription = subscribeToResult_1.subscribeToResult(this, retries);
  56. }
  57. else {
  58. this.errors = null;
  59. this.retriesSubscription = null;
  60. }
  61. this._unsubscribeAndRecycle();
  62. this.errors = errors;
  63. this.retries = retries;
  64. this.retriesSubscription = retriesSubscription;
  65. errors.next(err);
  66. }
  67. };
  68. RetryWhenSubscriber.prototype._unsubscribe = function () {
  69. var _a = this, errors = _a.errors, retriesSubscription = _a.retriesSubscription;
  70. if (errors) {
  71. errors.unsubscribe();
  72. this.errors = null;
  73. }
  74. if (retriesSubscription) {
  75. retriesSubscription.unsubscribe();
  76. this.retriesSubscription = null;
  77. }
  78. this.retries = null;
  79. };
  80. RetryWhenSubscriber.prototype.notifyNext = function (outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  81. var _unsubscribe = this._unsubscribe;
  82. this._unsubscribe = null;
  83. this._unsubscribeAndRecycle();
  84. this._unsubscribe = _unsubscribe;
  85. this.source.subscribe(this);
  86. };
  87. return RetryWhenSubscriber;
  88. }(OuterSubscriber_1.OuterSubscriber));
  89. //# sourceMappingURL=retryWhen.js.map