обычными методами никак, но:
console.log(1);
setTimeout(function() {
console.log(2);
console.log(3);
}, 1000);
function delay(timeout) {
return new Promise(function(resolve) {
setTimeout(resolve, timeout || 0);
});
}
console.log(1);
delay(1000).then(function() {
console.log(2);
}).then(function() {
console.log(3);
});
babel with preset-stage-3:
function delay(timeout) {
return new Promise(function(resolve) {
setTimeout(resolve, timeout || 0);
});
}
async function log123() {
console.log(1);
await delay(1000);
console.log(2);
console.log(3);
}
async function log1to10() {
for(var i = 1; i <= 10; i++) {
console.log(i);
await delay(i * 1000);
}
}
log123().then(function() {
return log1to10();
});