var timer = 0;
for (let i = 0; i < 10; i++) {
timer+=100;
setTimeout(()=> {
console.log(i);
}, timer);
}
function end() {
console.log("THE END");
}
end()
var timer = 0;
const callbacks = [];
for (let i = 0; i <= 10; i++) {
timer += 100;
callbacks.push(promisedTimeout(() => {
console.log(i);
return i;
}, timer)) ;
}
function promisedTimeout(callback, timer) {
return new Promise((resolve, reject) => {
setTimeout(() => {
return resolve(callback());
}, timer)
});
}
function end() {
Promise.all(callbacks)
.then(res => console.log("THE END"))
}
end()