Answers for "promise settimeout"

0

promise settimeout

await new Promise(resolve => setTimeout(resolve, 1000))
Posted by: Guest on June-03-2021
1

promise with timeout js

const promiseWithTimeout = promise => {
  let timeoutId;   
  const timeoutPromise = new Promise((_, reject) => {
    timeoutId = setTimeout(() => {      
      reject(new Error('Request timed out'));    
    }, 4000);  })
  return {
    promiseOrTimeout: Promise.race([promise, timeoutPromise]),
    timeoutId,  };
};
Posted by: Guest on June-01-2021

Browse Popular Code Answers by Language