一.promise
略。。。。。
二.generator
* nextID(max){
var n=0;
while(n<max){
yield n;
n++;
}
return
}
var f= this.nextID(5);
console.log(f.next());
var f= this.nextID(5);
for(var x of f){
console.log(x);
}
三.async/await
function timeout(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
async function asyncPrint(value, ms) {
await timeout(ms);
console.log(value)
}
asyncPrint('hello world', 2000);
两秒后打印结果:
总结了一下,现阶段似乎比较推荐使用第三方法。