Async Timeout
Async Timeout
Create a function that adds a timeout to any async function.
Requirements:
- Implement withTimeout that wraps an async function
- If the function doesn't complete within the timeout, reject with timeout error
- If it completes in time, resolve with the result
Example:
async function slowFunction() {
await sleep(1000);
return 'done';
}
const fastVersion = withTimeout(slowFunction, 500);
// This will reject with timeout error
Examples:
Input 1:
{"timeout":200}Output 1:
"success"Loading editor...
Run your code to see results
Click the Run button above