Skip to main content

Sleep / Delay

The sleep script module provides async delay functions for timing control within workflow scripts.

Functions

sleep

Pause script execution for a specified duration.

await sleep(ms)

Parameters:

ParameterTypeRequiredDescription
msnumberYesDuration in milliseconds (capped at 30,000ms)

Returns: void

delay

Alias for sleep.

await delay(ms)

wait

Alias for sleep.

await wait(ms)

Behavior

  • The maximum sleep duration is 30 seconds (30,000ms). Values above this are capped.
  • Negative values are treated as 0 (no delay).
  • The delay is implemented as a proper async operation and does not block the Node.js event loop.

Examples

Rate limiting API calls

const items = data.items;

for (const item of items) {
await processItem(item);
await sleep(200); // 200ms delay between API calls
}

Waiting for external processing

// Trigger an external process
await publishToWebhook(message);

// Wait for it to complete
await delay(2000);

// Check the result
const result = await checkStatus(id);
print('Status:', result);