Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

promise settimeout

await new Promise(resolve => setTimeout(resolve, 1000))
Comment

settime out with promise

const sleep = (time) => new Promise((resolve) => setTimeout(resolve, time));

await sleep(500)
// Do something after the sleep!

Comment

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,  };
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: Download Node Module With NPM 
Javascript :: javascript include property array object 
Javascript :: reverse sort array of objects 
Javascript :: js append to array 
Javascript :: javascript array contains 
Javascript :: pdf to json online 
Javascript :: Define the constructor property on the Dog prototype. 
Javascript :: random color 
Javascript :: react spring 
Javascript :: use appsettings.json in console app 
Javascript :: find an object from array of objects javascript 
Javascript :: console log 
Javascript :: how to use graphql api in react 
Javascript :: nodejs end process 
Javascript :: nestjs allow origin 
Javascript :: Best way to execute js only on specific page 
Javascript :: split and join in node js 
Javascript :: react hello world 
Javascript :: javascript check if visible 
Javascript :: javascript speech recognition 
Javascript :: javascript convert input to lowercase 
Javascript :: invoking jquery validator 
Javascript :: data table is not a function in vue 
Javascript :: all redux packages 
Javascript :: javascript new date invalid date dd/mm/yyyy 
Javascript :: express starting code 
Javascript :: storybook react router 
Javascript :: dom queryselector 
Javascript :: javascript check for duplicates in array 
Javascript :: javascript catch specific error 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =