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 :: laravel csrf token ajax post 
Javascript :: javascript random int in range 
Javascript :: first duplicate javascript 
Javascript :: nuxt js if is client 
Javascript :: copyright js 
Javascript :: hide and show modal in jquery 
Javascript :: javascript find a digit in str 
Javascript :: lottie react 
Javascript :: how to check if browser tab is active javascript 
Javascript :: how to run angular application in visual studio code 
Javascript :: angular goto top of page 
Javascript :: join text in js 
Javascript :: express get raw path 
Javascript :: moment get week day 
Javascript :: vue js required props 
Javascript :: how to get time and date from iso string javascript 
Javascript :: disable eslint 
Javascript :: how to loop through date range in javascript 
Javascript :: regex contains string in end 
Javascript :: js is numeric 
Javascript :: fibonacci javascript 
Javascript :: javascript json decode 
Javascript :: Get the Status Code of a Fetch HTTP Response 
Javascript :: sort javascript array 
Javascript :: vue on click router push not working 
Javascript :: javascript math pi 
Javascript :: javascript class 
Javascript :: alert with sound javascript 
Javascript :: how to import your external js 
Javascript :: javascript e.key 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =