retry.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /** PURE_IMPORTS_START tslib,_Subscriber PURE_IMPORTS_END */
  2. import * as tslib_1 from "tslib";
  3. import { Subscriber } from '../Subscriber';
  4. export function retry(count) {
  5. if (count === void 0) {
  6. count = -1;
  7. }
  8. return function (source) { return source.lift(new RetryOperator(count, source)); };
  9. }
  10. var RetryOperator = /*@__PURE__*/ (function () {
  11. function RetryOperator(count, source) {
  12. this.count = count;
  13. this.source = source;
  14. }
  15. RetryOperator.prototype.call = function (subscriber, source) {
  16. return source.subscribe(new RetrySubscriber(subscriber, this.count, this.source));
  17. };
  18. return RetryOperator;
  19. }());
  20. var RetrySubscriber = /*@__PURE__*/ (function (_super) {
  21. tslib_1.__extends(RetrySubscriber, _super);
  22. function RetrySubscriber(destination, count, source) {
  23. var _this = _super.call(this, destination) || this;
  24. _this.count = count;
  25. _this.source = source;
  26. return _this;
  27. }
  28. RetrySubscriber.prototype.error = function (err) {
  29. if (!this.isStopped) {
  30. var _a = this, source = _a.source, count = _a.count;
  31. if (count === 0) {
  32. return _super.prototype.error.call(this, err);
  33. }
  34. else if (count > -1) {
  35. this.count = count - 1;
  36. }
  37. source.subscribe(this._unsubscribeAndRecycle());
  38. }
  39. };
  40. return RetrySubscriber;
  41. }(Subscriber));
  42. //# sourceMappingURL=retry.js.map