⏳

Promise with Timeout

Promise with Timeout
보톡 비동기 +20pts

Problem

Write a function that wraps a promise with a timeout.

Examples

Input: await withTimeout(slowPromise, 1000)
Output: νƒ€μž„μ•„μ›ƒ μ‹œ μ—λŸ¬

Explanation

이 λ¬Έμ œλŠ” **Promise.race**λ₯Ό ν™œμš©ν•˜μ—¬ νƒ€μž„μ•„μ›ƒμ„ κ΅¬ν˜„ν•˜λŠ” 방법을 ν•™μŠ΅ν•©λ‹ˆλ‹€. ## 핡심 κ°œλ…: Promise νƒ€μž„μ•„μ›ƒ μ§€μ •λœ μ‹œκ°„ 내에 μ™„λ£Œλ˜μ§€ μ•ŠμœΌλ©΄ μ‹€νŒ¨ μ²˜λ¦¬ν•©λ‹ˆλ‹€. ### κ΅¬ν˜„ ```javascript function withTimeout(promise, ms) { const timeout = new Promise((_, reject) => setTimeout(() => reject(new Error('Timeout')), ms) ); return Promise.race([promise, ...

View detailed explanation β†’

Key Concepts

Promise νƒ€μž„μ•„μ›ƒ Promise.race setTimeout μ—λŸ¬ 처리
Time: O(1) Space: O(1)
solution.js
Ctrl + Enter
Run tests to see results here.