Skip to content

timing

const timing: object

Defined in: utils/timing.ts:254

Timing namespace object for convenient access.

humanDelay: (min, max) => Promise<void>

Sleep for a random duration (for human-like timing).

Useful for browser automation to appear more human-like.

number = 50

Minimum delay in milliseconds (default: 50)

number = 150

Maximum delay in milliseconds (default: 150)

Promise<void>

Promise that resolves after the random delay

// Default human-like delay (50-150ms)
await humanDelay();
// Custom range for slower actions
await humanDelay(100, 300);

randomDelay: (min, max) => number

Generate a random delay within a range.

number

Minimum delay in milliseconds

number

Maximum delay in milliseconds

number

Random integer between min and max (inclusive)

const delay = randomDelay(50, 150); // e.g., 87

withRetry: <T>(fn, options) => Promise<T>

Execute an async function with retry logic.

T

() => Promise<T>

Async function to execute

RetryOptions = {}

Retry options

Promise<T>

Promise that resolves with the function result or rejects after all retries exhausted

// Basic retry with defaults (3 retries, exponential backoff)
const result = await withRetry(() => unreliableApi());
// Custom retry configuration
const 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: <T>(fn, timeoutMs, signal?) => Promise<T>

Execute an async function with a timeout.

T

() => Promise<T>

Async function to execute

number

Timeout in milliseconds

AbortSignal

Optional AbortSignal for early cancellation

Promise<T>

Promise that resolves with the function result or rejects on timeout

Error with “Operation timed out” message if timeout is exceeded

const result = await withTimeout(
() => fetch("https://api.example.com/data"),
5000
);
// With abort signal
const controller = new AbortController();
const result = await withTimeout(
() => longRunningTask(),
30000,
controller.signal
);
import { timing } from "llmist";
await timing.humanDelay();
const result = await timing.withTimeout(() => fetch(url), 5000);
const data = await timing.withRetry(() => api.call(), { maxRetries: 3 });