5b6104a4ec58330e9fd61839fc8bf3915a20a0fe6f528df5e01cb91d74f83311c3a0665c680b7621c9e003c5f016b0ea462c13834d2ed747f1423754e8eba4 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { MonoTypeOperatorFunction, ObservableInput } from '../types';
  2. export interface RepeatConfig {
  3. /**
  4. * The number of times to repeat the source. Defaults to `Infinity`.
  5. */
  6. count?: number;
  7. /**
  8. * If a `number`, will delay the repeat of the source by that number of milliseconds.
  9. * If a function, it will provide the number of times the source has been subscribed to,
  10. * and the return value should be a valid observable input that will notify when the source
  11. * should be repeated. If the notifier observable is empty, the result will complete.
  12. */
  13. delay?: number | ((count: number) => ObservableInput<any>);
  14. }
  15. /**
  16. * Returns an Observable that will resubscribe to the source stream when the source stream completes.
  17. *
  18. * <span class="informal">Repeats all values emitted on the source. It's like {@link retry}, but for non error cases.</span>
  19. *
  20. * ![](repeat.png)
  21. *
  22. * Repeat will output values from a source until the source completes, then it will resubscribe to the
  23. * source a specified number of times, with a specified delay. Repeat can be particularly useful in
  24. * combination with closing operators like {@link take}, {@link takeUntil}, {@link first}, or {@link takeWhile},
  25. * as it can be used to restart a source again from scratch.
  26. *
  27. * Repeat is very similar to {@link retry}, where {@link retry} will resubscribe to the source in the error case, but
  28. * `repeat` will resubscribe if the source completes.
  29. *
  30. * Note that `repeat` will _not_ catch errors. Use {@link retry} for that.
  31. *
  32. * - `repeat(0)` returns an empty observable
  33. * - `repeat()` will repeat forever
  34. * - `repeat({ delay: 200 })` will repeat forever, with a delay of 200ms between repetitions.
  35. * - `repeat({ count: 2, delay: 400 })` will repeat twice, with a delay of 400ms between repetitions.
  36. * - `repeat({ delay: (count) => timer(count * 1000) })` will repeat forever, but will have a delay that grows by one second for each repetition.
  37. *
  38. * ## Example
  39. *
  40. * Repeat a message stream
  41. *
  42. * ```ts
  43. * import { of, repeat } from 'rxjs';
  44. *
  45. * const source = of('Repeat message');
  46. * const result = source.pipe(repeat(3));
  47. *
  48. * result.subscribe(x => console.log(x));
  49. *
  50. * // Results
  51. * // 'Repeat message'
  52. * // 'Repeat message'
  53. * // 'Repeat message'
  54. * ```
  55. *
  56. * Repeat 3 values, 2 times
  57. *
  58. * ```ts
  59. * import { interval, take, repeat } from 'rxjs';
  60. *
  61. * const source = interval(1000);
  62. * const result = source.pipe(take(3), repeat(2));
  63. *
  64. * result.subscribe(x => console.log(x));
  65. *
  66. * // Results every second
  67. * // 0
  68. * // 1
  69. * // 2
  70. * // 0
  71. * // 1
  72. * // 2
  73. * ```
  74. *
  75. * Defining two complex repeats with delays on the same source.
  76. * Note that the second repeat cannot be called until the first
  77. * repeat as exhausted it's count.
  78. *
  79. * ```ts
  80. * import { defer, of, repeat } from 'rxjs';
  81. *
  82. * const source = defer(() => {
  83. * return of(`Hello, it is ${new Date()}`)
  84. * });
  85. *
  86. * source.pipe(
  87. * // Repeat 3 times with a delay of 1 second between repetitions
  88. * repeat({
  89. * count: 3,
  90. * delay: 1000,
  91. * }),
  92. *
  93. * // *Then* repeat forever, but with an exponential step-back
  94. * // maxing out at 1 minute.
  95. * repeat({
  96. * delay: (count) => timer(Math.min(60000, 2 ^ count * 1000))
  97. * })
  98. * )
  99. * ```
  100. *
  101. * @see {@link repeatWhen}
  102. * @see {@link retry}
  103. *
  104. * @param countOrConfig Either the number of times the source Observable items are repeated
  105. * (a count of 0 will yield an empty Observable) or a {@link RepeatConfig} object.
  106. */
  107. export declare function repeat<T>(countOrConfig?: number | RepeatConfig): MonoTypeOperatorFunction<T>;
  108. //# sourceMappingURL=repeat.d.ts.map