es-toolkit/docs/reference/promise/delay.md
Minsoo Kim cf65b2c601
style(*): Setup prettier and apply formatting (#24)
* chore: add prettierrc

* chore: apply format with prettier config

* chore: eslint error fix
2024-06-04 17:19:26 +09:00

610 B

delay

Delays the execution of code for a specified number of milliseconds.

This function returns a Promise that resolves after the specified delay, allowing you to use it with async/await to pause execution.

Signature

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

Parameters

  • ms (number): The number of milliseconds to delay.

Returns

(Promise<void>): A Promise that resolves after the specified delay.

Examples

async function foo() {
  console.log('Start');
  await delay(1000); // Delays execution for 1 second
  console.log('End');
}

foo();