async&await

async function sleep(timeout) {
return new Promise((resolve, reject) => {
setTimeout(function() {
resolve('timeout');
}, timeout);
});
}


(async function() {
console.log('do something, ' + new Date());
await sleep(2000).then((value) => { console.log(value);});
console.log('Do other something, ' + new Date());
}());

原文地址:https://www.cnblogs.com/ax-null/p/6856656.html