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.
- package/dist/{duration.d.ts → di-BDlT7InM.d.cts} +15 -1
- package/dist/{duration.d.cts → di-BbFFfO8y.d.ts} +15 -1
- package/dist/errors-DtXvrCiO.d.cts +708 -0
- package/dist/errors-DtXvrCiO.d.ts +708 -0
- package/dist/index.cjs +4594 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1970 -141
- package/dist/index.d.ts +1970 -141
- package/dist/index.js +4398 -1
- package/dist/index.js.map +1 -1
- package/dist/result.cjs +641 -1
- package/dist/result.cjs.map +1 -1
- package/dist/result.d.cts +29 -4
- package/dist/result.d.ts +29 -4
- package/dist/result.js +561 -1
- package/dist/result.js.map +1 -1
- package/dist/testing.cjs +4202 -8
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +2 -6
- package/dist/testing.d.ts +2 -6
- package/dist/testing.js +4154 -8
- package/dist/testing.js.map +1 -1
- package/dist/{run-entry-DGs0tySr.d.cts → types-B8NfNRGX.d.ts} +1078 -1502
- package/dist/{run-entry-BOuNyVoO.d.ts → types-BZ2f4MRR.d.cts} +1078 -1502
- package/dist/workflow.cjs +7096 -6
- package/dist/workflow.cjs.map +1 -1
- package/dist/workflow.d.cts +3346 -22
- package/dist/workflow.d.ts +3346 -22
- package/dist/workflow.js +6929 -6
- package/dist/workflow.js.map +1 -1
- package/package.json +3 -168
- package/dist/adapters.cjs +0 -7
- package/dist/adapters.cjs.map +0 -1
- package/dist/adapters.d.cts +0 -179
- package/dist/adapters.d.ts +0 -179
- package/dist/adapters.js +0 -7
- package/dist/adapters.js.map +0 -1
- package/dist/batch.cjs +0 -7
- package/dist/batch.cjs.map +0 -1
- package/dist/batch.d.cts +0 -200
- package/dist/batch.d.ts +0 -200
- package/dist/batch.js +0 -7
- package/dist/batch.js.map +0 -1
- package/dist/bind-deps.cjs +0 -2
- package/dist/bind-deps.cjs.map +0 -1
- package/dist/bind-deps.d.cts +0 -28
- package/dist/bind-deps.d.ts +0 -28
- package/dist/bind-deps.js +0 -2
- package/dist/bind-deps.js.map +0 -1
- package/dist/cache.cjs +0 -2
- package/dist/cache.cjs.map +0 -1
- package/dist/cache.d.cts +0 -269
- package/dist/cache.d.ts +0 -269
- package/dist/cache.js +0 -2
- package/dist/cache.js.map +0 -1
- package/dist/circuit-breaker.cjs +0 -7
- package/dist/circuit-breaker.cjs.map +0 -1
- package/dist/circuit-breaker.d.cts +0 -211
- package/dist/circuit-breaker.d.ts +0 -211
- package/dist/circuit-breaker.js +0 -7
- package/dist/circuit-breaker.js.map +0 -1
- package/dist/conditional.cjs +0 -2
- package/dist/conditional.cjs.map +0 -1
- package/dist/conditional.d.cts +0 -252
- package/dist/conditional.d.ts +0 -252
- package/dist/conditional.js +0 -2
- package/dist/conditional.js.map +0 -1
- package/dist/core.cjs +0 -7
- package/dist/core.cjs.map +0 -1
- package/dist/core.d.cts +0 -5
- package/dist/core.d.ts +0 -5
- package/dist/core.js +0 -7
- package/dist/core.js.map +0 -1
- package/dist/di-By77n4Fa.d.ts +0 -15
- package/dist/di-OJfsohf-.d.cts +0 -15
- package/dist/diagnostics.cjs +0 -8
- package/dist/diagnostics.cjs.map +0 -1
- package/dist/diagnostics.d.cts +0 -68
- package/dist/diagnostics.d.ts +0 -68
- package/dist/diagnostics.js +0 -8
- package/dist/diagnostics.js.map +0 -1
- package/dist/durable.cjs +0 -11
- package/dist/durable.cjs.map +0 -1
- package/dist/durable.d.cts +0 -9
- package/dist/durable.d.ts +0 -9
- package/dist/durable.js +0 -11
- package/dist/durable.js.map +0 -1
- package/dist/duration.cjs +0 -2
- package/dist/duration.cjs.map +0 -1
- package/dist/duration.js +0 -2
- package/dist/duration.js.map +0 -1
- package/dist/engine.cjs +0 -11
- package/dist/engine.cjs.map +0 -1
- package/dist/engine.d.cts +0 -115
- package/dist/engine.d.ts +0 -115
- package/dist/engine.js +0 -11
- package/dist/engine.js.map +0 -1
- package/dist/errors.cjs +0 -2
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.d.cts +0 -361
- package/dist/errors.d.ts +0 -361
- package/dist/errors.js +0 -2
- package/dist/errors.js.map +0 -1
- package/dist/fetch.cjs +0 -7
- package/dist/fetch.cjs.map +0 -1
- package/dist/fetch.d.cts +0 -86
- package/dist/fetch.d.ts +0 -86
- package/dist/fetch.js +0 -7
- package/dist/fetch.js.map +0 -1
- package/dist/flow.cjs +0 -7
- package/dist/flow.cjs.map +0 -1
- package/dist/flow.d.cts +0 -163
- package/dist/flow.d.ts +0 -163
- package/dist/flow.js +0 -7
- package/dist/flow.js.map +0 -1
- package/dist/functional.cjs +0 -2
- package/dist/functional.cjs.map +0 -1
- package/dist/functional.d.cts +0 -444
- package/dist/functional.d.ts +0 -444
- package/dist/functional.js +0 -2
- package/dist/functional.js.map +0 -1
- package/dist/guards-4sV7mTqj.d.cts +0 -72
- package/dist/guards-BIX05ALH.d.ts +0 -72
- package/dist/hitl-DFn4Xa_l.d.cts +0 -468
- package/dist/hitl-DU5VpKq7.d.ts +0 -468
- package/dist/hitl.cjs +0 -7
- package/dist/hitl.cjs.map +0 -1
- package/dist/hitl.d.cts +0 -442
- package/dist/hitl.d.ts +0 -442
- package/dist/hitl.js +0 -7
- package/dist/hitl.js.map +0 -1
- package/dist/index-CnvBryQB.d.ts +0 -417
- package/dist/index-DEZEf8Fs.d.cts +0 -417
- package/dist/match-entry-DjI2bLpD.d.cts +0 -209
- package/dist/match-entry-DjI2bLpD.d.ts +0 -209
- package/dist/match.cjs +0 -2
- package/dist/match.cjs.map +0 -1
- package/dist/match.d.cts +0 -1
- package/dist/match.d.ts +0 -1
- package/dist/match.js +0 -2
- package/dist/match.js.map +0 -1
- package/dist/otel.cjs +0 -2
- package/dist/otel.cjs.map +0 -1
- package/dist/otel.d.cts +0 -188
- package/dist/otel.d.ts +0 -188
- package/dist/otel.js +0 -2
- package/dist/otel.js.map +0 -1
- package/dist/persistence-entry-B-8PjnSR.d.cts +0 -831
- package/dist/persistence-entry-D8zRkLiT.d.ts +0 -831
- package/dist/persistence.cjs +0 -2
- package/dist/persistence.cjs.map +0 -1
- package/dist/persistence.d.cts +0 -7
- package/dist/persistence.d.ts +0 -7
- package/dist/persistence.js +0 -2
- package/dist/persistence.js.map +0 -1
- package/dist/policies.cjs +0 -2
- package/dist/policies.cjs.map +0 -1
- package/dist/policies.d.cts +0 -379
- package/dist/policies.d.ts +0 -379
- package/dist/policies.js +0 -2
- package/dist/policies.js.map +0 -1
- package/dist/ratelimit.cjs +0 -7
- package/dist/ratelimit.cjs.map +0 -1
- package/dist/ratelimit.d.cts +0 -458
- package/dist/ratelimit.d.ts +0 -458
- package/dist/ratelimit.js +0 -7
- package/dist/ratelimit.js.map +0 -1
- package/dist/reliability.cjs +0 -11
- package/dist/reliability.cjs.map +0 -1
- package/dist/reliability.d.cts +0 -11
- package/dist/reliability.d.ts +0 -11
- package/dist/reliability.js +0 -11
- package/dist/reliability.js.map +0 -1
- package/dist/resolver.cjs +0 -7
- package/dist/resolver.cjs.map +0 -1
- package/dist/resolver.d.cts +0 -68
- package/dist/resolver.d.ts +0 -68
- package/dist/resolver.js +0 -7
- package/dist/resolver.js.map +0 -1
- package/dist/resource.cjs +0 -7
- package/dist/resource.cjs.map +0 -1
- package/dist/resource.d.cts +0 -174
- package/dist/resource.d.ts +0 -174
- package/dist/resource.js +0 -7
- package/dist/resource.js.map +0 -1
- package/dist/result/retry.cjs +0 -2
- package/dist/result/retry.cjs.map +0 -1
- package/dist/result/retry.d.cts +0 -70
- package/dist/result/retry.d.ts +0 -70
- package/dist/result/retry.js +0 -2
- package/dist/result/retry.js.map +0 -1
- package/dist/retry.cjs +0 -2
- package/dist/retry.cjs.map +0 -1
- package/dist/retry.d.cts +0 -388
- package/dist/retry.d.ts +0 -388
- package/dist/retry.js +0 -2
- package/dist/retry.js.map +0 -1
- package/dist/run.cjs +0 -7
- package/dist/run.cjs.map +0 -1
- package/dist/run.d.cts +0 -4
- package/dist/run.d.ts +0 -4
- package/dist/run.js +0 -7
- package/dist/run.js.map +0 -1
- package/dist/saga.cjs +0 -11
- package/dist/saga.cjs.map +0 -1
- package/dist/saga.d.cts +0 -164
- package/dist/saga.d.ts +0 -164
- package/dist/saga.js +0 -11
- package/dist/saga.js.map +0 -1
- package/dist/singleflight.cjs +0 -2
- package/dist/singleflight.cjs.map +0 -1
- package/dist/singleflight.d.cts +0 -145
- package/dist/singleflight.d.ts +0 -145
- package/dist/singleflight.js +0 -2
- package/dist/singleflight.js.map +0 -1
- package/dist/slugs.cjs +0 -2
- package/dist/slugs.cjs.map +0 -1
- package/dist/slugs.d.cts +0 -67
- package/dist/slugs.d.ts +0 -67
- package/dist/slugs.js +0 -2
- package/dist/slugs.js.map +0 -1
- package/dist/streaming.cjs +0 -9
- package/dist/streaming.cjs.map +0 -1
- package/dist/streaming.d.cts +0 -596
- package/dist/streaming.d.ts +0 -596
- package/dist/streaming.js +0 -9
- package/dist/streaming.js.map +0 -1
- package/dist/tagged-error.cjs +0 -2
- package/dist/tagged-error.cjs.map +0 -1
- package/dist/tagged-error.d.cts +0 -275
- package/dist/tagged-error.d.ts +0 -275
- package/dist/tagged-error.js +0 -2
- package/dist/tagged-error.js.map +0 -1
- package/dist/types-BziYHFkD.d.ts +0 -323
- package/dist/types-C5jLEUqY.d.cts +0 -323
- package/dist/webhook.cjs +0 -7
- package/dist/webhook.cjs.map +0 -1
- package/dist/webhook.d.cts +0 -499
- package/dist/webhook.d.ts +0 -499
- package/dist/webhook.js +0 -7
- 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 };
|