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 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { Subject } from '../Subject';
  2. import { OuterSubscriber } from '../OuterSubscriber';
  3. import { subscribeToResult } from '../util/subscribeToResult';
  4. export function retryWhen(notifier) {
  5. return (source) => source.lift(new RetryWhenOperator(notifier, source));
  6. }
  7. class RetryWhenOperator {
  8. constructor(notifier, source) {
  9. this.notifier = notifier;
  10. this.source = source;
  11. }
  12. call(subscriber, source) {
  13. return source.subscribe(new RetryWhenSubscriber(subscriber, this.notifier, this.source));
  14. }
  15. }
  16. class RetryWhenSubscriber extends OuterSubscriber {
  17. constructor(destination, notifier, source) {
  18. super(destination);
  19. this.notifier = notifier;
  20. this.source = source;
  21. }
  22. error(err) {
  23. if (!this.isStopped) {
  24. let errors = this.errors;
  25. let retries = this.retries;
  26. let retriesSubscription = this.retriesSubscription;
  27. if (!retries) {
  28. errors = new Subject();
  29. try {
  30. const { notifier } = this;
  31. retries = notifier(errors);
  32. }
  33. catch (e) {
  34. return super.error(e);
  35. }
  36. retriesSubscription = subscribeToResult(this, retries);
  37. }
  38. else {
  39. this.errors = null;
  40. this.retriesSubscription = null;
  41. }
  42. this._unsubscribeAndRecycle();
  43. this.errors = errors;
  44. this.retries = retries;
  45. this.retriesSubscription = retriesSubscription;
  46. errors.next(err);
  47. }
  48. }
  49. _unsubscribe() {
  50. const { errors, retriesSubscription } = this;
  51. if (errors) {
  52. errors.unsubscribe();
  53. this.errors = null;
  54. }
  55. if (retriesSubscription) {
  56. retriesSubscription.unsubscribe();
  57. this.retriesSubscription = null;
  58. }
  59. this.retries = null;
  60. }
  61. notifyNext(outerValue, innerValue, outerIndex, innerIndex, innerSub) {
  62. const { _unsubscribe } = this;
  63. this._unsubscribe = null;
  64. this._unsubscribeAndRecycle();
  65. this._unsubscribe = _unsubscribe;
  66. this.source.subscribe(this);
  67. }
  68. }
  69. //# sourceMappingURL=retryWhen.js.map