Skip to content

delay

Delay execution for a specified time.

Usage

js
import { delay } from 'js-cool'

Signature

typescript
function delay(ms: number): Promise<void>

Parameters

ParameterTypeDescription
msnumberMilliseconds to wait

Returns

Promise<void> - Resolves after delay.

Examples

js
await delay(1000) // Wait 1 second
console.log('After 1 second')

// In async function
async function loadData() {
  await delay(500)
  return fetch('/api/data')
}

Released under the MIT License.