mirror of
https://github.com/toss/es-toolkit.git
synced 2024-12-01 02:33:54 +03:00
b31b3a6964
* 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>
573 B
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 withTimeoutError
.
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'
}