retryWhen.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.retryWhen = void 0;
  4. var innerFrom_1 = require("../observable/innerFrom");
  5. var Subject_1 = require("../Subject");
  6. var lift_1 = require("../util/lift");
  7. var OperatorSubscriber_1 = require("./OperatorSubscriber");
  8. function retryWhen(notifier) {
  9. return lift_1.operate(function (source, subscriber) {
  10. var innerSub;
  11. var syncResub = false;
  12. var errors$;
  13. var subscribeForRetryWhen = function () {
  14. innerSub = source.subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, undefined, undefined, function (err) {
  15. if (!errors$) {
  16. errors$ = new Subject_1.Subject();
  17. innerFrom_1.innerFrom(notifier(errors$)).subscribe(OperatorSubscriber_1.createOperatorSubscriber(subscriber, function () {
  18. return innerSub ? subscribeForRetryWhen() : (syncResub = true);
  19. }));
  20. }
  21. if (errors$) {
  22. errors$.next(err);
  23. }
  24. }));
  25. if (syncResub) {
  26. innerSub.unsubscribe();
  27. innerSub = null;
  28. syncResub = false;
  29. subscribeForRetryWhen();
  30. }
  31. };
  32. subscribeForRetryWhen();
  33. });
  34. }
  35. exports.retryWhen = retryWhen;
  36. //# sourceMappingURL=retryWhen.js.map