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.
@@ -1,17 +1,28 @@
1
1
  /**
2
- * Waits for a condition to become true, polling at intervals.
2
+ * Waits for a condition to become truthy, polling at intervals.
3
3
  *
4
- * @param {Function} condition - returns truthy when satisfied
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'] - poll frequency
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] - Optional AbortSignal to cancel waiting
10
- * @returns {Promise<void>}
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: Function, { interval, timeout, immediate, signal }?: {
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<void>;
28
+ }): Promise<T>;