MediumPro challengePythonJavaScriptTypeScript

Promise Timeout

AsyncPromises

Implement withTimeout(promise, ms) that races a given promise against a
timeout. If the promise resolves before ms milliseconds, return its value.
Otherwise throw/reject with 'TIMEOUT'.

solve(resolveAfter, timeoutMs) simulates this by creating a promise that
resolves with 'done' after resolveAfter ms.

Sample tests

Test #1Resolves before timeout
Input: [10,100]
Output: {"value":"done","status":"ok"}
Test #2Timeout fires first
Input: [200,50]
Output: {"value":"TIMEOUT","status":"error"}
Test #3Immediate resolve
Input: [0,100]
Output: {"value":"done","status":"ok"}
Test #4Equal delays — promise wins (resolves at the edge)
Input: [100,100]
Output: {"value":"done","status":"ok"}
Test #5Very long resolve, very short timeout
Input: [500,10]
Output: {"value":"TIMEOUT","status":"error"}