Loading...
By continuing to use the platform, you accept the terms of the Privacy Policy and the use of cookies.
Write asyncTimeout(fn, delay) function that takes an async function and timeout duration in milliseconds.
asyncTimeout(fn, delay)
Requirements:
const slowFn = async (n) => { await sleep(1000); return n * 2; }; const fastFn = asyncTimeout(slowFn, 500); await fastFn(5); // Error: Timeout exceeded
Run your code to see results.
Click the Run button above