timeout-flow 0.0.19 → 0.1.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/ADDITIONAL_TERMS.md +122 -122
- package/LICENSE +694 -694
- package/README.md +475 -307
- package/dist/timeout-flow.min.js +1 -1
- package/package.json +79 -68
- 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 +137 -132
- package/src/abort.js +87 -75
- package/src/after.js +32 -32
- 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 +43 -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 +314 -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 +65 -89
- package/src/retry.js +205 -164
- package/src/sleep.js +58 -0
- package/src/throttle.js +141 -141
- package/src/waitFor.js +99 -77
- package/types/TimerBase.d.ts +2 -2
- package/types/abort.d.ts +9 -0
- package/types/index.d.ts +1 -0
- package/types/raf/waitForRaf.d.ts +1 -1
- package/types/resolveDelayAndFn.d.ts +1 -15
- package/types/retry.d.ts +57 -18
- package/types/sleep.d.ts +29 -0
- package/types/waitFor.d.ts +19 -8
package/types/waitFor.d.ts
CHANGED
|
@@ -1,17 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Waits for a condition to become
|
|
2
|
+
* Waits for a condition to become truthy, polling at intervals.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Timing model:
|
|
5
|
+
* - With `immediate: false` (default) the first check runs after `interval`.
|
|
6
|
+
* - The next check is scheduled `interval` after the previous one finishes,
|
|
7
|
+
* so async conditions never overlap.
|
|
8
|
+
* - `timeout` is measured from the call and enforced by its own timer, so it
|
|
9
|
+
* is not rounded up to the next poll. At the deadline a sync condition gets
|
|
10
|
+
* one final check (success at exactly `timeout` counts, like `>=`); an async
|
|
11
|
+
* check still pending at the deadline is abandoned and the promise rejects.
|
|
12
|
+
*
|
|
13
|
+
* @template T
|
|
14
|
+
* @param {() => T | Promise<T>} condition - sync or async; truthy when satisfied
|
|
5
15
|
* @param {Object} [options] - optional polling control
|
|
6
|
-
* @param {string|number} [options.interval='250ms'] -
|
|
7
|
-
* @param {string|number} [options.timeout] - max wait time
|
|
16
|
+
* @param {string|number} [options.interval='250ms'] - delay between checks
|
|
17
|
+
* @param {string|number} [options.timeout] - max wait time; rejects with an
|
|
18
|
+
* Error named 'TimeoutError' (message 'waitFor timed out')
|
|
8
19
|
* @param {boolean} [options.immediate=false] - If true, evaluate condition immediately
|
|
9
|
-
* @param {AbortSignal} [options.signal] -
|
|
10
|
-
* @returns {Promise<
|
|
20
|
+
* @param {AbortSignal} [options.signal] - rejects with `signal.reason` on abort
|
|
21
|
+
* @returns {Promise<T>} resolves with the condition's truthy value
|
|
11
22
|
*/
|
|
12
|
-
export function waitFor(condition:
|
|
23
|
+
export function waitFor<T>(condition: () => T | Promise<T>, { interval, timeout, immediate, signal }?: {
|
|
13
24
|
interval?: string | number | undefined;
|
|
14
25
|
timeout?: string | number | undefined;
|
|
15
26
|
immediate?: boolean | undefined;
|
|
16
27
|
signal?: AbortSignal | undefined;
|
|
17
|
-
}): Promise<
|
|
28
|
+
}): Promise<T>;
|