awaitly 1.35.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (241) hide show
  1. package/dist/{duration.d.ts → di-BDlT7InM.d.cts} +15 -1
  2. package/dist/{duration.d.cts → di-BbFFfO8y.d.ts} +15 -1
  3. package/dist/errors-DtXvrCiO.d.cts +708 -0
  4. package/dist/errors-DtXvrCiO.d.ts +708 -0
  5. package/dist/index.cjs +4594 -1
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +1970 -141
  8. package/dist/index.d.ts +1970 -141
  9. package/dist/index.js +4398 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/result.cjs +641 -1
  12. package/dist/result.cjs.map +1 -1
  13. package/dist/result.d.cts +29 -4
  14. package/dist/result.d.ts +29 -4
  15. package/dist/result.js +561 -1
  16. package/dist/result.js.map +1 -1
  17. package/dist/testing.cjs +4202 -8
  18. package/dist/testing.cjs.map +1 -1
  19. package/dist/testing.d.cts +2 -6
  20. package/dist/testing.d.ts +2 -6
  21. package/dist/testing.js +4154 -8
  22. package/dist/testing.js.map +1 -1
  23. package/dist/{run-entry-DGs0tySr.d.cts → types-B8NfNRGX.d.ts} +1078 -1502
  24. package/dist/{run-entry-BOuNyVoO.d.ts → types-BZ2f4MRR.d.cts} +1078 -1502
  25. package/dist/workflow.cjs +7096 -6
  26. package/dist/workflow.cjs.map +1 -1
  27. package/dist/workflow.d.cts +3346 -22
  28. package/dist/workflow.d.ts +3346 -22
  29. package/dist/workflow.js +6929 -6
  30. package/dist/workflow.js.map +1 -1
  31. package/package.json +3 -168
  32. package/dist/adapters.cjs +0 -7
  33. package/dist/adapters.cjs.map +0 -1
  34. package/dist/adapters.d.cts +0 -179
  35. package/dist/adapters.d.ts +0 -179
  36. package/dist/adapters.js +0 -7
  37. package/dist/adapters.js.map +0 -1
  38. package/dist/batch.cjs +0 -7
  39. package/dist/batch.cjs.map +0 -1
  40. package/dist/batch.d.cts +0 -200
  41. package/dist/batch.d.ts +0 -200
  42. package/dist/batch.js +0 -7
  43. package/dist/batch.js.map +0 -1
  44. package/dist/bind-deps.cjs +0 -2
  45. package/dist/bind-deps.cjs.map +0 -1
  46. package/dist/bind-deps.d.cts +0 -28
  47. package/dist/bind-deps.d.ts +0 -28
  48. package/dist/bind-deps.js +0 -2
  49. package/dist/bind-deps.js.map +0 -1
  50. package/dist/cache.cjs +0 -2
  51. package/dist/cache.cjs.map +0 -1
  52. package/dist/cache.d.cts +0 -269
  53. package/dist/cache.d.ts +0 -269
  54. package/dist/cache.js +0 -2
  55. package/dist/cache.js.map +0 -1
  56. package/dist/circuit-breaker.cjs +0 -7
  57. package/dist/circuit-breaker.cjs.map +0 -1
  58. package/dist/circuit-breaker.d.cts +0 -211
  59. package/dist/circuit-breaker.d.ts +0 -211
  60. package/dist/circuit-breaker.js +0 -7
  61. package/dist/circuit-breaker.js.map +0 -1
  62. package/dist/conditional.cjs +0 -2
  63. package/dist/conditional.cjs.map +0 -1
  64. package/dist/conditional.d.cts +0 -252
  65. package/dist/conditional.d.ts +0 -252
  66. package/dist/conditional.js +0 -2
  67. package/dist/conditional.js.map +0 -1
  68. package/dist/core.cjs +0 -7
  69. package/dist/core.cjs.map +0 -1
  70. package/dist/core.d.cts +0 -5
  71. package/dist/core.d.ts +0 -5
  72. package/dist/core.js +0 -7
  73. package/dist/core.js.map +0 -1
  74. package/dist/di-By77n4Fa.d.ts +0 -15
  75. package/dist/di-OJfsohf-.d.cts +0 -15
  76. package/dist/diagnostics.cjs +0 -8
  77. package/dist/diagnostics.cjs.map +0 -1
  78. package/dist/diagnostics.d.cts +0 -68
  79. package/dist/diagnostics.d.ts +0 -68
  80. package/dist/diagnostics.js +0 -8
  81. package/dist/diagnostics.js.map +0 -1
  82. package/dist/durable.cjs +0 -11
  83. package/dist/durable.cjs.map +0 -1
  84. package/dist/durable.d.cts +0 -9
  85. package/dist/durable.d.ts +0 -9
  86. package/dist/durable.js +0 -11
  87. package/dist/durable.js.map +0 -1
  88. package/dist/duration.cjs +0 -2
  89. package/dist/duration.cjs.map +0 -1
  90. package/dist/duration.js +0 -2
  91. package/dist/duration.js.map +0 -1
  92. package/dist/engine.cjs +0 -11
  93. package/dist/engine.cjs.map +0 -1
  94. package/dist/engine.d.cts +0 -115
  95. package/dist/engine.d.ts +0 -115
  96. package/dist/engine.js +0 -11
  97. package/dist/engine.js.map +0 -1
  98. package/dist/errors.cjs +0 -2
  99. package/dist/errors.cjs.map +0 -1
  100. package/dist/errors.d.cts +0 -361
  101. package/dist/errors.d.ts +0 -361
  102. package/dist/errors.js +0 -2
  103. package/dist/errors.js.map +0 -1
  104. package/dist/fetch.cjs +0 -7
  105. package/dist/fetch.cjs.map +0 -1
  106. package/dist/fetch.d.cts +0 -86
  107. package/dist/fetch.d.ts +0 -86
  108. package/dist/fetch.js +0 -7
  109. package/dist/fetch.js.map +0 -1
  110. package/dist/flow.cjs +0 -7
  111. package/dist/flow.cjs.map +0 -1
  112. package/dist/flow.d.cts +0 -163
  113. package/dist/flow.d.ts +0 -163
  114. package/dist/flow.js +0 -7
  115. package/dist/flow.js.map +0 -1
  116. package/dist/functional.cjs +0 -2
  117. package/dist/functional.cjs.map +0 -1
  118. package/dist/functional.d.cts +0 -444
  119. package/dist/functional.d.ts +0 -444
  120. package/dist/functional.js +0 -2
  121. package/dist/functional.js.map +0 -1
  122. package/dist/guards-4sV7mTqj.d.cts +0 -72
  123. package/dist/guards-BIX05ALH.d.ts +0 -72
  124. package/dist/hitl-DFn4Xa_l.d.cts +0 -468
  125. package/dist/hitl-DU5VpKq7.d.ts +0 -468
  126. package/dist/hitl.cjs +0 -7
  127. package/dist/hitl.cjs.map +0 -1
  128. package/dist/hitl.d.cts +0 -442
  129. package/dist/hitl.d.ts +0 -442
  130. package/dist/hitl.js +0 -7
  131. package/dist/hitl.js.map +0 -1
  132. package/dist/index-CnvBryQB.d.ts +0 -417
  133. package/dist/index-DEZEf8Fs.d.cts +0 -417
  134. package/dist/match-entry-DjI2bLpD.d.cts +0 -209
  135. package/dist/match-entry-DjI2bLpD.d.ts +0 -209
  136. package/dist/match.cjs +0 -2
  137. package/dist/match.cjs.map +0 -1
  138. package/dist/match.d.cts +0 -1
  139. package/dist/match.d.ts +0 -1
  140. package/dist/match.js +0 -2
  141. package/dist/match.js.map +0 -1
  142. package/dist/otel.cjs +0 -2
  143. package/dist/otel.cjs.map +0 -1
  144. package/dist/otel.d.cts +0 -188
  145. package/dist/otel.d.ts +0 -188
  146. package/dist/otel.js +0 -2
  147. package/dist/otel.js.map +0 -1
  148. package/dist/persistence-entry-B-8PjnSR.d.cts +0 -831
  149. package/dist/persistence-entry-D8zRkLiT.d.ts +0 -831
  150. package/dist/persistence.cjs +0 -2
  151. package/dist/persistence.cjs.map +0 -1
  152. package/dist/persistence.d.cts +0 -7
  153. package/dist/persistence.d.ts +0 -7
  154. package/dist/persistence.js +0 -2
  155. package/dist/persistence.js.map +0 -1
  156. package/dist/policies.cjs +0 -2
  157. package/dist/policies.cjs.map +0 -1
  158. package/dist/policies.d.cts +0 -379
  159. package/dist/policies.d.ts +0 -379
  160. package/dist/policies.js +0 -2
  161. package/dist/policies.js.map +0 -1
  162. package/dist/ratelimit.cjs +0 -7
  163. package/dist/ratelimit.cjs.map +0 -1
  164. package/dist/ratelimit.d.cts +0 -458
  165. package/dist/ratelimit.d.ts +0 -458
  166. package/dist/ratelimit.js +0 -7
  167. package/dist/ratelimit.js.map +0 -1
  168. package/dist/reliability.cjs +0 -11
  169. package/dist/reliability.cjs.map +0 -1
  170. package/dist/reliability.d.cts +0 -11
  171. package/dist/reliability.d.ts +0 -11
  172. package/dist/reliability.js +0 -11
  173. package/dist/reliability.js.map +0 -1
  174. package/dist/resolver.cjs +0 -7
  175. package/dist/resolver.cjs.map +0 -1
  176. package/dist/resolver.d.cts +0 -68
  177. package/dist/resolver.d.ts +0 -68
  178. package/dist/resolver.js +0 -7
  179. package/dist/resolver.js.map +0 -1
  180. package/dist/resource.cjs +0 -7
  181. package/dist/resource.cjs.map +0 -1
  182. package/dist/resource.d.cts +0 -174
  183. package/dist/resource.d.ts +0 -174
  184. package/dist/resource.js +0 -7
  185. package/dist/resource.js.map +0 -1
  186. package/dist/result/retry.cjs +0 -2
  187. package/dist/result/retry.cjs.map +0 -1
  188. package/dist/result/retry.d.cts +0 -70
  189. package/dist/result/retry.d.ts +0 -70
  190. package/dist/result/retry.js +0 -2
  191. package/dist/result/retry.js.map +0 -1
  192. package/dist/retry.cjs +0 -2
  193. package/dist/retry.cjs.map +0 -1
  194. package/dist/retry.d.cts +0 -388
  195. package/dist/retry.d.ts +0 -388
  196. package/dist/retry.js +0 -2
  197. package/dist/retry.js.map +0 -1
  198. package/dist/run.cjs +0 -7
  199. package/dist/run.cjs.map +0 -1
  200. package/dist/run.d.cts +0 -4
  201. package/dist/run.d.ts +0 -4
  202. package/dist/run.js +0 -7
  203. package/dist/run.js.map +0 -1
  204. package/dist/saga.cjs +0 -11
  205. package/dist/saga.cjs.map +0 -1
  206. package/dist/saga.d.cts +0 -164
  207. package/dist/saga.d.ts +0 -164
  208. package/dist/saga.js +0 -11
  209. package/dist/saga.js.map +0 -1
  210. package/dist/singleflight.cjs +0 -2
  211. package/dist/singleflight.cjs.map +0 -1
  212. package/dist/singleflight.d.cts +0 -145
  213. package/dist/singleflight.d.ts +0 -145
  214. package/dist/singleflight.js +0 -2
  215. package/dist/singleflight.js.map +0 -1
  216. package/dist/slugs.cjs +0 -2
  217. package/dist/slugs.cjs.map +0 -1
  218. package/dist/slugs.d.cts +0 -67
  219. package/dist/slugs.d.ts +0 -67
  220. package/dist/slugs.js +0 -2
  221. package/dist/slugs.js.map +0 -1
  222. package/dist/streaming.cjs +0 -9
  223. package/dist/streaming.cjs.map +0 -1
  224. package/dist/streaming.d.cts +0 -596
  225. package/dist/streaming.d.ts +0 -596
  226. package/dist/streaming.js +0 -9
  227. package/dist/streaming.js.map +0 -1
  228. package/dist/tagged-error.cjs +0 -2
  229. package/dist/tagged-error.cjs.map +0 -1
  230. package/dist/tagged-error.d.cts +0 -275
  231. package/dist/tagged-error.d.ts +0 -275
  232. package/dist/tagged-error.js +0 -2
  233. package/dist/tagged-error.js.map +0 -1
  234. package/dist/types-BziYHFkD.d.ts +0 -323
  235. package/dist/types-C5jLEUqY.d.cts +0 -323
  236. package/dist/webhook.cjs +0 -7
  237. package/dist/webhook.cjs.map +0 -1
  238. package/dist/webhook.d.cts +0 -499
  239. package/dist/webhook.d.ts +0 -499
  240. package/dist/webhook.js +0 -7
  241. package/dist/webhook.js.map +0 -1
package/dist/retry.d.cts DELETED
@@ -1,388 +0,0 @@
1
- import { Duration } from './duration.cjs';
2
- export { days, hours, isDuration, millis, minutes, seconds, toDays, toHours, toMillis, toMinutes, toSeconds } from './duration.cjs';
3
-
4
- /**
5
- * awaitly/schedule
6
- *
7
- * Composable scheduling primitives inspired by Effect's Schedule module.
8
- * Build complex retry and polling strategies by composing simple building blocks.
9
- *
10
- * @example
11
- * ```typescript
12
- * // "Exponential backoff with jitter, max 5 attempts, then poll every minute"
13
- * const schedule = Schedule.exponential(Duration.millis(100))
14
- * .pipe(Schedule.jittered(0.2))
15
- * .pipe(Schedule.upTo(5))
16
- * .pipe(Schedule.andThen(Schedule.spaced(Duration.minutes(1))))
17
- *
18
- * // Use with workflows
19
- * const result = await step('fetchData', () => fetchData(), { schedule })
20
- * ```
21
- */
22
-
23
- /**
24
- * The state maintained by a schedule during execution.
25
- */
26
- interface ScheduleState {
27
- /** Number of iterations completed */
28
- readonly iterations: number;
29
- /** Total elapsed time since schedule started */
30
- readonly elapsed: Duration;
31
- /** The last input received (if any) */
32
- readonly lastInput?: unknown;
33
- /** The last output produced (if any) */
34
- readonly lastOutput?: unknown;
35
- /** Combinator-specific metadata (used by andThen, union, intersect, etc.) */
36
- readonly meta?: unknown;
37
- }
38
- /**
39
- * Decision returned by a schedule step.
40
- * Combinators can optionally provide `nextState` to thread custom state through execution.
41
- */
42
- type ScheduleDecision<Out> = {
43
- readonly _tag: "Continue";
44
- readonly delay: Duration;
45
- readonly output: Out;
46
- readonly nextState?: ScheduleState;
47
- } | {
48
- readonly _tag: "Done";
49
- };
50
- /**
51
- * A schedule that repeats forever with no delay.
52
- */
53
- declare function forever<In = unknown>(): Schedule<In, number>;
54
- /**
55
- * A schedule that repeats exactly n times.
56
- *
57
- * @example
58
- * ```typescript
59
- * const thrice = Schedule.recurs(3)
60
- * ```
61
- */
62
- declare function recurs<In = unknown>(n: number): Schedule<In, number>;
63
- /**
64
- * A schedule that repeats once.
65
- */
66
- declare function once<In = unknown>(): Schedule<In, void>;
67
- /**
68
- * A schedule that always stops immediately.
69
- */
70
- declare function stop<In = unknown>(): Schedule<In, never>;
71
- /**
72
- * A schedule that waits a fixed duration between each iteration.
73
- *
74
- * @example
75
- * ```typescript
76
- * const pollEvery5s = Schedule.spaced(Duration.seconds(5))
77
- * ```
78
- */
79
- declare function spaced<In = unknown>(delay: Duration): Schedule<In, number>;
80
- /**
81
- * Alias for spaced - a fixed interval schedule.
82
- */
83
- declare const fixed: typeof spaced;
84
- /**
85
- * A schedule with exponentially increasing delays.
86
- * delay(n) = base * factor^n
87
- *
88
- * @example
89
- * ```typescript
90
- * // 100ms, 200ms, 400ms, 800ms, ...
91
- * const exponential = Schedule.exponential(Duration.millis(100))
92
- *
93
- * // With custom factor: 100ms, 300ms, 900ms, ...
94
- * const triple = Schedule.exponential(Duration.millis(100), 3)
95
- * ```
96
- */
97
- declare function exponential<In = unknown>(base: Duration, factor?: number): Schedule<In, Duration>;
98
- /**
99
- * A schedule with linearly increasing delays.
100
- * delay(n) = base * (n + 1)
101
- *
102
- * @example
103
- * ```typescript
104
- * // 100ms, 200ms, 300ms, 400ms, ...
105
- * const linear = Schedule.linear(Duration.millis(100))
106
- * ```
107
- */
108
- declare function linear<In = unknown>(base: Duration): Schedule<In, Duration>;
109
- /**
110
- * A schedule with fibonacci-sequence delays.
111
- * delay(n) follows fibonacci: base, base, 2*base, 3*base, 5*base, ...
112
- *
113
- * @example
114
- * ```typescript
115
- * // 100ms, 100ms, 200ms, 300ms, 500ms, 800ms, ...
116
- * const fib = Schedule.fibonacci(Duration.millis(100))
117
- * ```
118
- */
119
- declare function fibonacci<In = unknown>(base: Duration): Schedule<In, Duration>;
120
- /**
121
- * Limit a schedule to at most n iterations.
122
- *
123
- * @example
124
- * ```typescript
125
- * // Exponential backoff, max 5 attempts
126
- * const limited = Schedule.exponential(Duration.millis(100))
127
- * .pipe(Schedule.upTo(5))
128
- * ```
129
- */
130
- declare function upTo<In, Out>(n: number): (schedule: Schedule<In, Out>) => Schedule<In, Out>;
131
- /**
132
- * Limit a schedule by total elapsed time.
133
- *
134
- * @example
135
- * ```typescript
136
- * // Retry for at most 30 seconds
137
- * const timeLimited = Schedule.spaced(Duration.seconds(1))
138
- * .pipe(Schedule.upToElapsed(Duration.seconds(30)))
139
- * ```
140
- */
141
- declare function upToElapsed<In, Out>(maxElapsed: Duration): (schedule: Schedule<In, Out>) => Schedule<In, Out>;
142
- /**
143
- * Cap the maximum delay of a schedule.
144
- *
145
- * @example
146
- * ```typescript
147
- * // Exponential, but never more than 30 seconds
148
- * const capped = Schedule.exponential(Duration.millis(100))
149
- * .pipe(Schedule.maxDelay(Duration.seconds(30)))
150
- * ```
151
- */
152
- declare function maxDelay<In, Out>(max: Duration): (schedule: Schedule<In, Out>) => Schedule<In, Out>;
153
- /**
154
- * Set a minimum delay for a schedule.
155
- *
156
- * @example
157
- * ```typescript
158
- * const atLeast1s = schedule.pipe(Schedule.minDelay(Duration.seconds(1)))
159
- * ```
160
- */
161
- declare function minDelay<In, Out>(min: Duration): (schedule: Schedule<In, Out>) => Schedule<In, Out>;
162
- /**
163
- * Continue while a predicate on the input returns true.
164
- *
165
- * @example
166
- * ```typescript
167
- * // Retry while the error is transient
168
- * const retryTransient = Schedule.exponential(Duration.millis(100))
169
- * .pipe(Schedule.whileInput((err: Error) => err.message.includes("ECONNRESET")))
170
- * ```
171
- */
172
- declare function whileInput<In, Out>(predicate: (input: In) => boolean): (schedule: Schedule<In, Out>) => Schedule<In, Out>;
173
- /**
174
- * Continue while a predicate on the output returns true.
175
- *
176
- * @example
177
- * ```typescript
178
- * // Poll until status is "ready"
179
- * const untilReady = Schedule.spaced(Duration.seconds(1))
180
- * .pipe(Schedule.whileOutput((status: string) => status !== "ready"))
181
- * ```
182
- */
183
- declare function whileOutput<In, Out>(predicate: (output: Out) => boolean): (schedule: Schedule<In, Out>) => Schedule<In, Out>;
184
- /**
185
- * Continue until a predicate on the input returns true.
186
- * Opposite of whileInput.
187
- */
188
- declare function untilInput<In, Out>(predicate: (input: In) => boolean): (schedule: Schedule<In, Out>) => Schedule<In, Out>;
189
- /**
190
- * Continue until a predicate on the output returns true.
191
- * Opposite of whileOutput.
192
- */
193
- declare function untilOutput<In, Out>(predicate: (output: Out) => boolean): (schedule: Schedule<In, Out>) => Schedule<In, Out>;
194
- /**
195
- * Add random jitter to delays to prevent thundering herd.
196
- *
197
- * @param factor - Jitter factor (0.0 to 1.0). Delay will be multiplied by (1 - factor) to (1 + factor).
198
- *
199
- * @example
200
- * ```typescript
201
- * // ±20% jitter
202
- * const jittered = Schedule.exponential(Duration.millis(100))
203
- * .pipe(Schedule.jittered(0.2))
204
- * ```
205
- */
206
- declare function jittered<In, Out>(factor?: number): (schedule: Schedule<In, Out>) => Schedule<In, Out>;
207
- /**
208
- * Add a fixed random delay to each iteration.
209
- *
210
- * @example
211
- * ```typescript
212
- * // Add 0-500ms random delay
213
- * const randomized = schedule.pipe(Schedule.addDelay(Duration.millis(500)))
214
- * ```
215
- */
216
- declare function addDelay<In, Out>(maxExtra: Duration): (schedule: Schedule<In, Out>) => Schedule<In, Out>;
217
- /**
218
- * Chain two schedules: run the first until done, then run the second.
219
- * The second schedule starts with fresh state when it begins.
220
- *
221
- * @example
222
- * ```typescript
223
- * // 5 exponential retries, then poll every minute
224
- * const strategy = Schedule.exponential(Duration.millis(100))
225
- * .pipe(Schedule.upTo(5))
226
- * .pipe(Schedule.andThen(Schedule.spaced(Duration.minutes(1))))
227
- * ```
228
- */
229
- declare function andThen<In, Out1, Out2>(second: Schedule<In, Out2>): (first: Schedule<In, Out1>) => Schedule<In, Out1 | Out2>;
230
- /**
231
- * Run two schedules in parallel, using the shorter delay.
232
- * Both schedules advance their state independently.
233
- *
234
- * @example
235
- * ```typescript
236
- * // Use whichever delay is shorter
237
- * const union = Schedule.union(
238
- * Schedule.exponential(Duration.millis(100)),
239
- * Schedule.spaced(Duration.seconds(1))
240
- * )
241
- * ```
242
- */
243
- declare function union<In, Out1, Out2>(first: Schedule<In, Out1>, second: Schedule<In, Out2>): Schedule<In, [Out1, Out2]>;
244
- /**
245
- * Run two schedules in parallel, using the longer delay.
246
- * Both schedules advance their state independently. Stops when either schedule stops.
247
- *
248
- * @example
249
- * ```typescript
250
- * // Use whichever delay is longer
251
- * const intersect = Schedule.intersect(
252
- * Schedule.exponential(Duration.millis(100)),
253
- * Schedule.spaced(Duration.seconds(1))
254
- * )
255
- * ```
256
- */
257
- declare function intersect<In, Out1, Out2>(first: Schedule<In, Out1>, second: Schedule<In, Out2>): Schedule<In, [Out1, Out2]>;
258
- /**
259
- * Transform the output of a schedule.
260
- *
261
- * @example
262
- * ```typescript
263
- * const withIteration = Schedule.spaced(Duration.seconds(1))
264
- * .pipe(Schedule.map((n) => ({ attempt: n + 1 })))
265
- * ```
266
- */
267
- declare function map<In, Out, NewOut>(fn: (output: Out) => NewOut): (schedule: Schedule<In, Out>) => Schedule<In, NewOut>;
268
- /**
269
- * Perform a side effect on each iteration.
270
- *
271
- * @example
272
- * ```typescript
273
- * const logged = Schedule.exponential(Duration.millis(100))
274
- * .pipe(Schedule.tap((delay) => console.log(`Waiting ${delay}ms`)))
275
- * ```
276
- */
277
- declare function tap<In, Out>(fn: (output: Out, state: ScheduleState) => void): (schedule: Schedule<In, Out>) => Schedule<In, Out>;
278
- /**
279
- * Modify the delay of a schedule.
280
- *
281
- * @example
282
- * ```typescript
283
- * const doubled = schedule.pipe(Schedule.modifyDelay(d => Duration.multiply(d, 2)))
284
- * ```
285
- */
286
- declare function modifyDelay<In, Out>(fn: (delay: Duration, output: Out) => Duration): (schedule: Schedule<In, Out>) => Schedule<In, Out>;
287
- /**
288
- * Create an iterator for running a schedule step-by-step.
289
- *
290
- * @example
291
- * ```typescript
292
- * const runner = Schedule.run(mySchedule)
293
- *
294
- * while (true) {
295
- * const next = runner.next(lastResult)
296
- * if (next.done) break
297
- * await sleep(next.value.delay)
298
- * }
299
- * ```
300
- */
301
- declare function run<In, Out>(schedule: Schedule<In, Out>): {
302
- next: (input: In) => {
303
- done: false;
304
- value: {
305
- delay: Duration;
306
- output: Out;
307
- };
308
- } | {
309
- done: true;
310
- };
311
- };
312
- /**
313
- * Get all delays from a schedule (for testing/visualization).
314
- * Runs the schedule with undefined input until it completes or reaches maxIterations.
315
- */
316
- declare function delays<Out>(schedule: Schedule<undefined, Out>, maxIterations?: number): Duration[];
317
- /**
318
- * A schedule with pipe support for method chaining.
319
- */
320
- type PipedSchedule<In, Out> = Schedule<In, Out> & {
321
- pipe: <NewOut>(fn: (s: Schedule<In, Out>) => Schedule<In, NewOut>) => PipedSchedule<In, NewOut>;
322
- } & {
323
- pipe: <R>(fn: (s: Schedule<In, Out>) => R) => R;
324
- };
325
- /**
326
- * A Schedule defines a recurring pattern with delays and outputs.
327
- *
328
- * @typeParam In - The input type (from retry attempts, etc.)
329
- * @typeParam Out - The output type (often the delay or iteration count)
330
- */
331
- interface Schedule<In = unknown, Out = unknown> {
332
- readonly _tag: "Schedule";
333
- /** Compute the next step given input and current state */
334
- readonly step: (input: In, state: ScheduleState) => ScheduleDecision<Out>;
335
- /** Initial state for this schedule */
336
- readonly initial: ScheduleState;
337
- }
338
- /**
339
- * Schedule namespace for composable scheduling.
340
- *
341
- * @example
342
- * ```typescript
343
- * import { Schedule, Duration } from "awaitly";
344
- *
345
- * // Exponential backoff with jitter, max 5 attempts
346
- * const retry = Schedule.exponential(Duration.millis(100))
347
- * .pipe(Schedule.jittered(0.2))
348
- * .pipe(Schedule.upTo(5))
349
- * .pipe(Schedule.maxDelay(Duration.seconds(30)))
350
- *
351
- * // Then poll every minute forever
352
- * const poll = Schedule.spaced(Duration.minutes(1))
353
- *
354
- * // Chain them
355
- * const strategy = retry.pipe(Schedule.andThen(poll))
356
- * ```
357
- */
358
- declare const Schedule: {
359
- readonly forever: <In = unknown>() => PipedSchedule<In, number>;
360
- readonly once: <In = unknown>() => PipedSchedule<In, void>;
361
- readonly recurs: <In = unknown>(n: number) => PipedSchedule<In, number>;
362
- readonly stop: typeof stop;
363
- readonly spaced: <In = unknown>(delay: Duration) => PipedSchedule<In, number>;
364
- readonly fixed: <In = unknown>(delay: Duration) => PipedSchedule<In, number>;
365
- readonly exponential: <In = unknown>(base: Duration, factor?: number) => PipedSchedule<In, Duration>;
366
- readonly linear: <In = unknown>(base: Duration) => PipedSchedule<In, Duration>;
367
- readonly fibonacci: <In = unknown>(base: Duration) => PipedSchedule<In, Duration>;
368
- readonly upTo: typeof upTo;
369
- readonly upToElapsed: typeof upToElapsed;
370
- readonly maxDelay: typeof maxDelay;
371
- readonly minDelay: typeof minDelay;
372
- readonly whileInput: typeof whileInput;
373
- readonly whileOutput: typeof whileOutput;
374
- readonly untilInput: typeof untilInput;
375
- readonly untilOutput: typeof untilOutput;
376
- readonly jittered: typeof jittered;
377
- readonly addDelay: typeof addDelay;
378
- readonly andThen: typeof andThen;
379
- readonly union: <In, Out1, Out2>(first: Schedule<In, Out1>, second: Schedule<In, Out2>) => PipedSchedule<In, [Out1, Out2]>;
380
- readonly intersect: <In, Out1, Out2>(first: Schedule<In, Out1>, second: Schedule<In, Out2>) => PipedSchedule<In, [Out1, Out2]>;
381
- readonly map: typeof map;
382
- readonly tap: typeof tap;
383
- readonly modifyDelay: typeof modifyDelay;
384
- readonly run: typeof run;
385
- readonly delays: typeof delays;
386
- };
387
-
388
- export { Duration, Duration as DurationType, Schedule, type ScheduleDecision, type ScheduleState, Schedule as ScheduleType, addDelay, andThen, delays, exponential, fibonacci, fixed, forever, intersect, jittered, linear, map, maxDelay, minDelay, modifyDelay, once, recurs, run, spaced, stop, tap, union, untilInput, untilOutput, upTo, upToElapsed, whileInput, whileOutput };