retryWhen.js 1.1 KB

123456789101112131415161718192021222324252627282930
  1. import { innerFrom } from '../observable/innerFrom';
  2. import { Subject } from '../Subject';
  3. import { operate } from '../util/lift';
  4. import { createOperatorSubscriber } from './OperatorSubscriber';
  5. export function retryWhen(notifier) {
  6. return operate((source, subscriber) => {
  7. let innerSub;
  8. let syncResub = false;
  9. let errors$;
  10. const subscribeForRetryWhen = () => {
  11. innerSub = source.subscribe(createOperatorSubscriber(subscriber, undefined, undefined, (err) => {
  12. if (!errors$) {
  13. errors$ = new Subject();
  14. innerFrom(notifier(errors$)).subscribe(createOperatorSubscriber(subscriber, () => innerSub ? subscribeForRetryWhen() : (syncResub = true)));
  15. }
  16. if (errors$) {
  17. errors$.next(err);
  18. }
  19. }));
  20. if (syncResub) {
  21. innerSub.unsubscribe();
  22. innerSub = null;
  23. syncResub = false;
  24. subscribeForRetryWhen();
  25. }
  26. };
  27. subscribeForRetryWhen();
  28. });
  29. }
  30. //# sourceMappingURL=retryWhen.js.map