JSFiddle - React, Tailwind, and code Playground
by ppgab
JavaScript
class MyClass{
constructor(t){
this.time = t
}
load(){
return new Promise(resolve => {
setTimeout( () => {
console.log(this.time);
resolve(this.time);
}, 1000/this.time)
})
}
}
let pChain;
for(let i=1; i<=5; i++){
if(!pChain){
pChain = new MyClass(i).load();
}else{
pChain = pChain.then( t => new MyClass(i).load())
}
}
pChain.then();