settimeout promise
作者:互联网
setTimeout(function(){
alert("Sup!");
}, 2000);//wait 2 seconds
settime out with promise
Javascript By Marwen Labidi on Feb 22 2022
const sleep = (time) => new Promise((resolve) => setTimeout(resolve, time));
await sleep(500)
// Do something after the sleep!
promise with timeout js
Javascript By Maximauve_ on Jun 1 2021 Donate
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, };
};
标签:timeoutId,const,setTimeout,promise,Promise,new,settimeout 来源: https://www.cnblogs.com/sexintercourse/p/16454168.html