timeout-flow 0.0.19 → 0.0.20
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/ADDITIONAL_TERMS.md +122 -122
- package/LICENSE +694 -694
- package/README.md +453 -307
- package/dist/timeout-flow.min.js +1 -1
- package/package.json +12 -6
- package/robots.txt +79 -79
- package/src/AfterTimer.js +81 -81
- package/src/EveryTimer.js +208 -208
- package/src/TimeoutFlow.js +400 -400
- package/src/TimerBase.js +133 -132
- package/src/abort.js +87 -75
- package/src/after.js +32 -32
- package/src/context-js.bat +58 -0
- package/src/context.txt +2709 -0
- package/src/debounce.js +105 -105
- package/src/every.js +34 -34
- package/src/index.js +24 -23
- package/src/now.js +22 -22
- package/src/parseDuration.js +46 -46
- package/src/raf/ReadMe-Raf.md +94 -94
- package/src/raf/afterRaf.js +203 -203
- package/src/raf/debounceRaf.js +126 -126
- package/src/raf/everyRaf.js +316 -316
- package/src/raf/index.js +27 -27
- package/src/raf/throttleRaf.js +181 -181
- package/src/raf/waitForRaf.js +100 -100
- package/src/resolveDelayAndFn.js +89 -89
- package/src/retry.js +205 -164
- package/src/sleep.js +58 -0
- package/src/throttle.js +141 -141
- package/src/waitFor.js +96 -77
- package/types/abort.d.ts +40 -31
- package/types/index.d.ts +10 -9
- package/types/raf/waitForRaf.d.ts +19 -19
- package/types/retry.d.ts +70 -31
- package/types/sleep.d.ts +29 -0
- package/types/waitFor.d.ts +28 -17
package/README.md
CHANGED
|
@@ -1,307 +1,453 @@
|
|
|
1
|
-
# timeout-flow
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/timeout-flow)
|
|
4
|
-
[](https://www.npmjs.com/package/timeout-flow)
|
|
5
|
-
[](https://bundlephobia.com/package/timeout-flow)
|
|
6
|
-
[](https://github.com/iWhatty/
|
|
7
|
-
[](https://www.npmjs.com/package/timeout-flow)
|
|
4
|
+
[](https://www.npmjs.com/package/timeout-flow)
|
|
5
|
+
[](https://bundlephobia.com/package/timeout-flow)
|
|
6
|
+
[](https://github.com/iWhatty/timeout-flow/blob/main/LICENSE)
|
|
7
|
+
[](https://github.com/iWhatty/timeout-flow)
|
|
8
|
+
[](https://www.npmjs.com/package/timeout-flow)
|
|
9
|
+
|
|
10
|
+
Fluent, human-readable time control for JavaScript. A modern, composable upgrade to `setTimeout` and `setInterval` with chaining, conditional logic, pause/resume control, retries, and RAF utilities.
|
|
11
|
+
|
|
12
|
+
## Features
|
|
13
|
+
|
|
14
|
+
- Readable durations: `"1s"`, `"500ms"`, plain numbers
|
|
15
|
+
- Pause / resume / cancel controllers for `after()`, `every()`, RAF variants
|
|
16
|
+
- `flow()` builds declarative timelines with branching and labels
|
|
17
|
+
- `sleep()` promise delay with `AbortSignal` cancellation
|
|
18
|
+
- `retry()` with fixed/linear/exponential backoff, jitter, deadlines, result predicates and hooks
|
|
19
|
+
- `waitFor()` polls a sync or async predicate with an exact timeout
|
|
20
|
+
- RAF variants (`afterRaf`, `everyRaf`, `debounceRaf`, `throttleRaf`, `waitForRaf`) for frame-aligned timing
|
|
21
|
+
- ESM-first, tree-shakeable. Per-file subpath exports for size-sensitive consumers (~1.2 KB gzipped for a single primitive)
|
|
22
|
+
- Zero dependencies
|
|
23
|
+
- ~15 KB minified for the full kit (~5.5 KB gzipped)
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Install
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
pnpm add timeout-flow
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Quick start
|
|
36
|
+
|
|
37
|
+
```js
|
|
38
|
+
import { after } from 'timeout-flow';
|
|
39
|
+
|
|
40
|
+
function greet() {
|
|
41
|
+
console.log('Hello');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const ctrl = after('2s', greet);
|
|
45
|
+
|
|
46
|
+
ctrl.pause();
|
|
47
|
+
ctrl.resume();
|
|
48
|
+
ctrl.cancel();
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## API
|
|
54
|
+
|
|
55
|
+
### `after(duration, fn, options?)`
|
|
56
|
+
|
|
57
|
+
Run once after a delay.
|
|
58
|
+
|
|
59
|
+
```js
|
|
60
|
+
import { after } from 'timeout-flow';
|
|
61
|
+
|
|
62
|
+
after('2s', function greet() {
|
|
63
|
+
console.log('Hello');
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### `every(duration, fn, options?)`
|
|
68
|
+
|
|
69
|
+
Repeat execution with optional limit.
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
import { every } from 'timeout-flow';
|
|
73
|
+
|
|
74
|
+
const ticker = every('1s', function tick(i) {
|
|
75
|
+
console.log('Tick', i);
|
|
76
|
+
}, { max: 5 });
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### `debounce(duration, fn, options?)`
|
|
80
|
+
|
|
81
|
+
Delay execution until inactivity.
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
import { debounce } from 'timeout-flow';
|
|
85
|
+
|
|
86
|
+
const debouncedSearch = debounce('300ms', function search(event) {
|
|
87
|
+
console.log('Searching for:', event.target.value);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
debouncedSearch.cancel();
|
|
91
|
+
debouncedSearch.flush();
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### `throttle(duration, fn, options?)`
|
|
95
|
+
|
|
96
|
+
Limit execution frequency.
|
|
97
|
+
|
|
98
|
+
```js
|
|
99
|
+
import { throttle } from 'timeout-flow';
|
|
100
|
+
|
|
101
|
+
const onScroll = throttle('250ms', function handleScroll() {
|
|
102
|
+
console.log('scroll');
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
onScroll.cancel();
|
|
106
|
+
onScroll.flush();
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### `sleep(duration?, options?)`
|
|
110
|
+
|
|
111
|
+
Promise-based delay with the same duration format as everything else.
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
import { sleep } from 'timeout-flow';
|
|
115
|
+
|
|
116
|
+
await sleep('500ms');
|
|
117
|
+
await sleep(250);
|
|
118
|
+
|
|
119
|
+
// Cancelable: rejects with signal.reason (an AbortError by default)
|
|
120
|
+
// and clears its timer.
|
|
121
|
+
const ac = new AbortController();
|
|
122
|
+
await sleep('10s', { signal: ac.signal });
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
* Numbers behave like `setTimeout`: `NaN` and negative values wait 0 ms.
|
|
126
|
+
* Huge values (including `Infinity`) are capped at ~24.8 days instead of
|
|
127
|
+
overflowing and firing immediately.
|
|
128
|
+
* Invalid strings (e.g. `'soon'`) reject; `sleep()` never throws synchronously.
|
|
129
|
+
|
|
130
|
+
### `retry(fn, options?)`
|
|
131
|
+
|
|
132
|
+
Retry sync or async work with delays, backoff, jitter, deadlines and hooks.
|
|
133
|
+
|
|
134
|
+
```js
|
|
135
|
+
import { retry } from 'timeout-flow';
|
|
136
|
+
|
|
137
|
+
async function fetchData() {
|
|
138
|
+
return fetch('/api/data');
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
await retry(fetchData, {
|
|
142
|
+
attempts: 5,
|
|
143
|
+
delay: '500ms',
|
|
144
|
+
backoff: true,
|
|
145
|
+
factor: 2,
|
|
146
|
+
maxDelay: '5s',
|
|
147
|
+
jitter: 'decorrelated'
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
| Option | Default | Meaning |
|
|
152
|
+
| --- | --- | --- |
|
|
153
|
+
| `attempts` | `3` | Total attempts including the first. `Infinity` is allowed (pair it with `timeout`). |
|
|
154
|
+
| `delay` | `'500ms'` | Base delay between attempts. |
|
|
155
|
+
| `backoff` | `false` | `false`/`'fixed'`, `'linear'` (`delay * (n+1)`), `true`/`'exponential'` (`delay * factor^n`). |
|
|
156
|
+
| `factor` | `2` | Exponential multiplier. |
|
|
157
|
+
| `maxDelay` | none | Cap applied to every computed delay. |
|
|
158
|
+
| `jitter` | `false` | `true`/`'full'`, `'equal'`, `'decorrelated'`, or a number `j` in `[0, 1]` for proportional ±j jitter (`delay * (1 + (random()*2 - 1) * j)`, applied after the `maxDelay` cap and re-capped by it, never below 0). Other numbers or `NaN` reject with a `RangeError` before any attempt. `delayFirst` is never jittered. Delays are rounded to whole ms. |
|
|
159
|
+
| `delayFirst` | `false` | Wait before the first attempt: `true` uses `delay`, or pass a duration. |
|
|
160
|
+
| `timeout` | none | Overall deadline from the call. No retry starts after it; an in-flight attempt is not interrupted and the first attempt always runs. |
|
|
161
|
+
| `isSuccess(result, attempt)` | none | Return `false` to treat a resolved result as a failure and retry. |
|
|
162
|
+
| `shouldRetry(error, attempt)` | none | Return `false` to stop retrying. |
|
|
163
|
+
| `onAttempt(attempt, elapsedMs)` | none | Called before every attempt. |
|
|
164
|
+
| `onRetry(error, attempt, delayMs)` | none | Called after deciding to retry, before waiting. |
|
|
165
|
+
| `signal` | none | Abort waiting and further attempts. |
|
|
166
|
+
| `sleep(ms, { signal })` | built-in `sleep` | Injectable wait, e.g. for fake-timer tests. |
|
|
167
|
+
| `now()` | `performance.now` | Injectable clock used for `timeout`. |
|
|
168
|
+
| `random()` | `Math.random` | Injectable RNG for jitter. |
|
|
169
|
+
|
|
170
|
+
Attempt numbers are **0-based** everywhere (`fn(attempt)`, hooks, predicates).
|
|
171
|
+
|
|
172
|
+
Outcome:
|
|
173
|
+
|
|
174
|
+
* Resolves with the first successful result.
|
|
175
|
+
* Otherwise rejects with the **last failure**: the last thrown error as-is, or,
|
|
176
|
+
if the last attempt resolved with a result `isSuccess` rejected, an error
|
|
177
|
+
with `name: 'RetryError'`, `.result` (that last result) and `.attempts`.
|
|
178
|
+
* On abort, rejects with `signal.reason` (an `AbortError` by default).
|
|
179
|
+
|
|
180
|
+
#### Retry recipes
|
|
181
|
+
|
|
182
|
+
Retry until a result looks right, with a little log line per attempt:
|
|
183
|
+
|
|
184
|
+
```js
|
|
185
|
+
const response = await retry(() => sendMessage(tabId, msg), {
|
|
186
|
+
attempts: 4,
|
|
187
|
+
delay: 200,
|
|
188
|
+
backoff: 'exponential',
|
|
189
|
+
maxDelay: '2s',
|
|
190
|
+
isSuccess: (res) => res?.ok === true,
|
|
191
|
+
onAttempt: (attempt, elapsed) => console.debug('attempt', attempt, Math.round(elapsed), 'ms'),
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Exponential backoff with ±15% proportional jitter:
|
|
196
|
+
|
|
197
|
+
```js
|
|
198
|
+
await retry(poll, {
|
|
199
|
+
attempts: 5,
|
|
200
|
+
delay: 200,
|
|
201
|
+
backoff: true,
|
|
202
|
+
factor: 1.6,
|
|
203
|
+
maxDelay: '1500ms',
|
|
204
|
+
jitter: 0.15, // each wait lands within 85%..115% of its computed delay
|
|
205
|
+
});
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Time-bounded retry (deadline instead of an attempt count):
|
|
209
|
+
|
|
210
|
+
```js
|
|
211
|
+
await retry(() => connect(), {
|
|
212
|
+
attempts: Infinity,
|
|
213
|
+
delay: '250ms',
|
|
214
|
+
timeout: '5s',
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
Give something a moment to settle before the first try, and stop on fatal errors:
|
|
219
|
+
|
|
220
|
+
```js
|
|
221
|
+
await retry(loadConfig, {
|
|
222
|
+
delayFirst: '100ms',
|
|
223
|
+
attempts: 3,
|
|
224
|
+
backoff: 'linear',
|
|
225
|
+
shouldRetry: (err) => err.name !== 'SyntaxError',
|
|
226
|
+
});
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
Return a result object instead of throwing:
|
|
230
|
+
|
|
231
|
+
```js
|
|
232
|
+
const outcome = await retry(task, { attempts: 3 }).then(
|
|
233
|
+
(value) => ({ ok: true, value }),
|
|
234
|
+
(error) => ({ ok: false, error, value: error?.result })
|
|
235
|
+
);
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Deterministic tests without real timers:
|
|
239
|
+
|
|
240
|
+
```js
|
|
241
|
+
let clock = 0;
|
|
242
|
+
const waits = [];
|
|
243
|
+
|
|
244
|
+
await retry(task, {
|
|
245
|
+
attempts: 4,
|
|
246
|
+
delay: 100,
|
|
247
|
+
backoff: true,
|
|
248
|
+
now: () => clock,
|
|
249
|
+
sleep: async (ms) => { waits.push(ms); clock += ms; },
|
|
250
|
+
}).catch(() => {});
|
|
251
|
+
|
|
252
|
+
// waits -> [100, 200, 400]
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### `waitFor(predicate, options?)`
|
|
256
|
+
|
|
257
|
+
Wait until a condition becomes truthy. Resolves with the condition's value.
|
|
258
|
+
|
|
259
|
+
```js
|
|
260
|
+
import { waitFor } from 'timeout-flow';
|
|
261
|
+
|
|
262
|
+
const el = await waitFor(function findLoaded() {
|
|
263
|
+
return document.querySelector('#loaded');
|
|
264
|
+
}, {
|
|
265
|
+
interval: '250ms',
|
|
266
|
+
timeout: '5s',
|
|
267
|
+
immediate: true
|
|
268
|
+
});
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Timing model:
|
|
272
|
+
|
|
273
|
+
* The first check runs after `interval` unless `immediate: true`.
|
|
274
|
+
* Conditions may be async; the next check is scheduled `interval` after the
|
|
275
|
+
previous one settles, so checks never overlap.
|
|
276
|
+
* `timeout` is measured from the call and has its own timer, so it is not
|
|
277
|
+
rounded up to the next poll. At the deadline a sync condition gets one final
|
|
278
|
+
check, so success at exactly `timeout` counts (`elapsed >= timeout` times out
|
|
279
|
+
only if the condition is still falsy). It rejects with an `Error` named
|
|
280
|
+
`'TimeoutError'` (message `'waitFor timed out'`).
|
|
281
|
+
* `signal` rejects with `signal.reason`.
|
|
282
|
+
|
|
283
|
+
`waitForRaf()` checks once per animation frame and measures `timeout` from the
|
|
284
|
+
first frame's timestamp (RAF time), timing out once `elapsed >= timeout`.
|
|
285
|
+
|
|
286
|
+
### `flow()`
|
|
287
|
+
|
|
288
|
+
Build declarative time flows.
|
|
289
|
+
|
|
290
|
+
```js
|
|
291
|
+
import { flow } from 'timeout-flow';
|
|
292
|
+
|
|
293
|
+
flow()
|
|
294
|
+
.after('1s', function stepOne() {
|
|
295
|
+
console.log('Step 1');
|
|
296
|
+
})
|
|
297
|
+
.every('500ms', function tick(i) {
|
|
298
|
+
console.log('Tick', i);
|
|
299
|
+
}, { max: 3 })
|
|
300
|
+
.after('1s', function finalStep() {
|
|
301
|
+
console.log('Final Step');
|
|
302
|
+
})
|
|
303
|
+
.start();
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Flow reads like a timeline and keeps duration-first ordering for readability.
|
|
307
|
+
|
|
308
|
+
### RAF utilities
|
|
309
|
+
|
|
310
|
+
Frame-based timing powered by `requestAnimationFrame`. Ideal for visual updates, scroll handlers, layout checks, and animation loops.
|
|
311
|
+
|
|
312
|
+
Available: `afterRaf()`, `everyRaf()`, `debounceRaf()`, `throttleRaf()`, `waitForRaf()`.
|
|
313
|
+
|
|
314
|
+
```js
|
|
315
|
+
import { throttleRaf } from 'timeout-flow';
|
|
316
|
+
|
|
317
|
+
const onScroll = throttleRaf(function drawFrame() {
|
|
318
|
+
console.log('draw');
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
onScroll.cancel();
|
|
322
|
+
onScroll.flush();
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Controllers
|
|
326
|
+
|
|
327
|
+
Most time-based primitives return a controller object:
|
|
328
|
+
|
|
329
|
+
```js
|
|
330
|
+
const ctrl = after('1s', () => console.log('done'));
|
|
331
|
+
|
|
332
|
+
ctrl.pause();
|
|
333
|
+
ctrl.resume();
|
|
334
|
+
ctrl.cancel();
|
|
335
|
+
ctrl.reset?.();
|
|
336
|
+
|
|
337
|
+
console.log(ctrl.isRunning);
|
|
338
|
+
console.log(ctrl.isPaused);
|
|
339
|
+
console.log(ctrl.isFinished);
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
Shared by `after()`, `every()`, `afterRaf()`, `everyRaf()`. All controllers are pause-safe (paused time does not count), cancel-safe, monotonic-time based, and `AbortSignal`-aware where supported.
|
|
343
|
+
|
|
344
|
+
### AbortSignal support
|
|
345
|
+
|
|
346
|
+
Many utilities accept `{ signal }` for automatic cancellation.
|
|
347
|
+
|
|
348
|
+
```js
|
|
349
|
+
import { after } from 'timeout-flow';
|
|
350
|
+
|
|
351
|
+
const ac = new AbortController();
|
|
352
|
+
|
|
353
|
+
after('2s', function doWork() {
|
|
354
|
+
console.log('Will not run if aborted');
|
|
355
|
+
}, { signal: ac.signal });
|
|
356
|
+
|
|
357
|
+
ac.abort();
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
If already aborted at creation time, no work is scheduled.
|
|
361
|
+
|
|
362
|
+
### Public surface
|
|
363
|
+
|
|
364
|
+
```js
|
|
365
|
+
import {
|
|
366
|
+
after,
|
|
367
|
+
every,
|
|
368
|
+
debounce,
|
|
369
|
+
throttle,
|
|
370
|
+
sleep,
|
|
371
|
+
retry,
|
|
372
|
+
waitFor,
|
|
373
|
+
flow,
|
|
374
|
+
|
|
375
|
+
afterRaf,
|
|
376
|
+
everyRaf,
|
|
377
|
+
debounceRaf,
|
|
378
|
+
throttleRaf,
|
|
379
|
+
waitForRaf
|
|
380
|
+
} from 'timeout-flow';
|
|
381
|
+
```
|
|
382
|
+
|
|
383
|
+
---
|
|
384
|
+
|
|
385
|
+
## Notes
|
|
386
|
+
|
|
387
|
+
### Tree-shaking and per-primitive imports
|
|
388
|
+
|
|
389
|
+
Two import styles, same package, choose by bundle-size sensitivity:
|
|
390
|
+
|
|
391
|
+
```js
|
|
392
|
+
// Full kit. Every primitive available on one import.
|
|
393
|
+
// Modern bundlers (esbuild, vite, rollup, webpack 5) will tree-shake
|
|
394
|
+
// unused exports because the package ships `sideEffects: false` and the
|
|
395
|
+
// `.` entrypoint points at ESM source instead of a pre-minified blob.
|
|
396
|
+
import { after, debounce, retry } from 'timeout-flow';
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
```js
|
|
400
|
+
// Per-primitive subpath. Explicit minimum surface, useful when you know
|
|
401
|
+
// you only need one primitive and want the bundle to reflect that
|
|
402
|
+
// without relying on the bundler's tree-shaker. Same source either way.
|
|
403
|
+
import { after } from 'timeout-flow/after';
|
|
404
|
+
import { every } from 'timeout-flow/every';
|
|
405
|
+
import { debounce } from 'timeout-flow/debounce';
|
|
406
|
+
import { throttle } from 'timeout-flow/throttle';
|
|
407
|
+
import { sleep } from 'timeout-flow/sleep';
|
|
408
|
+
import { retry } from 'timeout-flow/retry';
|
|
409
|
+
import { waitFor } from 'timeout-flow/wait-for';
|
|
410
|
+
import { flow } from 'timeout-flow/flow';
|
|
411
|
+
import { afterRaf, everyRaf, debounceRaf, throttleRaf, waitForRaf } from 'timeout-flow/raf';
|
|
412
|
+
import { parseDuration } from 'timeout-flow/parse-duration';
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
Measured for a single `after()` call in a typical browser bundler (esbuild, minified + gzip):
|
|
416
|
+
|
|
417
|
+
| Import style | Gzip |
|
|
418
|
+
|---|---:|
|
|
419
|
+
| pre-0.0.19 default (full minified bundle) | 5098 bytes |
|
|
420
|
+
| 0.0.19 default (`import { after } from 'timeout-flow'`) | 1199 bytes |
|
|
421
|
+
| 0.0.19 subpath (`import { after } from 'timeout-flow/after'`) | 1199 bytes |
|
|
422
|
+
|
|
423
|
+
For unbundled `<script type="module">` consumption of the full kit, use the **`timeout-flow/min`** subpath, which points at the pre-built minified IIFE.
|
|
424
|
+
|
|
425
|
+
### Clean signatures
|
|
426
|
+
|
|
427
|
+
timeout-flow supports both natural-language and function-first argument ordering:
|
|
428
|
+
|
|
429
|
+
```js
|
|
430
|
+
after('1s', done);
|
|
431
|
+
// or
|
|
432
|
+
after(done, '1s');
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
This applies to `after()`, `every()`, `debounce()`, `throttle()`. Use whichever reads best in your codebase.
|
|
436
|
+
|
|
437
|
+
### Philosophy
|
|
438
|
+
|
|
439
|
+
timeout-flow is not just a wrapper around timers, it's a composable toolkit for expressing time as readable logic. Temporal behavior should be:
|
|
440
|
+
|
|
441
|
+
- **Readable.** Durations like `"1s"` and `"500ms"` beat magic numbers.
|
|
442
|
+
- **Composable.** Sequencing should be declarative.
|
|
443
|
+
- **Controllable.** Timers should pause, resume, cancel.
|
|
444
|
+
- **Branchable.** Real flows need `if`, `while`, `label`, `jumpTo()`.
|
|
445
|
+
- **Tiny.** No runtime bloat.
|
|
446
|
+
|
|
447
|
+
> Think of timeout-flow as `setTimeout()` with superpowers.
|
|
448
|
+
|
|
449
|
+
---
|
|
450
|
+
|
|
451
|
+
## License
|
|
452
|
+
|
|
453
|
+
Licensed under AGPL-3.0 with WATT3D Additional Terms. See [LICENSE](./LICENSE) and [ADDITIONAL_TERMS.md](./ADDITIONAL_TERMS.md). Commercial AI/model-training use requires compliance with those terms or a separate WATT3D license. © WATT3D.
|