-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
// function start(id) {
// setTimeout(() => {
// execute(id).catch(console.error)
// }, id * 1000)
// }
function start(id) {
this.promise = this.promise
? this.promise.then(_ => execute(id))
: execute(id);
}
// 测试代码 (请勿更改):
for (let i = 0; i < 5; i++) {
start(i);
}
function sleep() {
const duration = Math.floor(Math.random() * 500);
return new Promise(resolve => setTimeout(resolve, duration));
}
function execute(id) {
return sleep().then(() => {
console.log("id", id);
});
}imondo