es-toolkit/docs/reference/promise/timeout.md
Seung Ju b31b3a6964
feat(withTimeout): add withTimeout function (#210)
* feat(timeout): add timeout function

* feat(timeout): timeout to withTimeout

* Update docs/ko/reference/promise/withTimeout.md

* Update docs/ko/reference/promise/withTimeout.md

* feat(timeout): timeout, withTimeout

* Update docs/ko/reference/promise/timeout.md

* Update docs/ko/reference/promise/timeout.md

* Update withTimeout.ts

* Update timeout.ts

* Apply suggestions from code review

* Update withTimeout.md

* Update withTimeout.spec.ts

* Update src/promise/withTimeout.spec.ts

---------

Co-authored-by: Sojin Park <raon0211@gmail.com>
Co-authored-by: Sojin Park <raon0211@toss.im>
2024-07-18 21:37:33 +09:00

573 B

timeout

Returns a Promise that rejects with a TimeoutError after the specified timeout.

Signature

function timeout(ms: number): Promise<never>;

Parameters

  • ms (number): The number of milliseconds for the promise to reject with TimeoutError.

Returns

(Promise<never>): A Promise that rejects after the specified timeout.

예시

기본 사용법

try {
  await timeout(1000); // Timeout exception after 1 second
} catch (error) {
  console.error(error); // Will log 'The operation was timed out'
}