timing
consttiming:object
Defined in: utils/timing.ts:254
Timing namespace object for convenient access.
Type Declaration
Section titled “Type Declaration”humanDelay()
Section titled “humanDelay()”humanDelay: (
min,max) =>Promise<void>
Sleep for a random duration (for human-like timing).
Useful for browser automation to appear more human-like.
Parameters
Section titled “Parameters”number = 50
Minimum delay in milliseconds (default: 50)
number = 150
Maximum delay in milliseconds (default: 150)
Returns
Section titled “Returns”Promise<void>
Promise that resolves after the random delay
Example
Section titled “Example”// Default human-like delay (50-150ms)await humanDelay();
// Custom range for slower actionsawait humanDelay(100, 300);randomDelay()
Section titled “randomDelay()”randomDelay: (
min,max) =>number
Generate a random delay within a range.
Parameters
Section titled “Parameters”number
Minimum delay in milliseconds
number
Maximum delay in milliseconds
Returns
Section titled “Returns”number
Random integer between min and max (inclusive)
Example
Section titled “Example”const delay = randomDelay(50, 150); // e.g., 87withRetry()
Section titled “withRetry()”withRetry: <
T>(fn,options) =>Promise<T>
Execute an async function with retry logic.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”() => Promise<T>
Async function to execute
options
Section titled “options”RetryOptions = {}
Retry options
Returns
Section titled “Returns”Promise<T>
Promise that resolves with the function result or rejects after all retries exhausted
Example
Section titled “Example”// Basic retry with defaults (3 retries, exponential backoff)const result = await withRetry(() => unreliableApi());
// Custom retry configurationconst result = await withRetry( () => fetchWithErrors(), { maxRetries: 5, delay: 500, backoff: "exponential", shouldRetry: (error) => error.status === 429 || error.status >= 500, onRetry: (error, attempt, delay) => { console.log(`Retry ${attempt} after ${delay}ms`); } });withTimeout()
Section titled “withTimeout()”withTimeout: <
T>(fn,timeoutMs,signal?) =>Promise<T>
Execute an async function with a timeout.
Type Parameters
Section titled “Type Parameters”T
Parameters
Section titled “Parameters”() => Promise<T>
Async function to execute
timeoutMs
Section titled “timeoutMs”number
Timeout in milliseconds
signal?
Section titled “signal?”AbortSignal
Optional AbortSignal for early cancellation
Returns
Section titled “Returns”Promise<T>
Promise that resolves with the function result or rejects on timeout
Throws
Section titled “Throws”Error with “Operation timed out” message if timeout is exceeded
Example
Section titled “Example”const result = await withTimeout( () => fetch("https://api.example.com/data"), 5000);
// With abort signalconst controller = new AbortController();const result = await withTimeout( () => longRunningTask(), 30000, controller.signal);Example
Section titled “Example”import { timing } from "llmist";
await timing.humanDelay();const result = await timing.withTimeout(() => fetch(url), 5000);const data = await timing.withRetry(() => api.call(), { maxRetries: 3 });