Answers for "settimeout promise"

150

javascript settimeout

setTimeout(function(){
 	alert("Sup!"); 
}, 2000);//wait 2 seconds
Posted by: Guest on June-27-2019
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

Code answers related to "Javascript"

Browse Popular Code Answers by Language