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.