decorator, async/await, generator
2017-09-25 00:45
309 查看
////////////decorator////////// function aopFunc (target, key, descriptor) { console.log('aopFunc') } class foo { @aopFunc bar () { console.log('fooo') } } ///////////////////////////// ///////////generator/////////// function* asyncFunc () { var index = 0; while (index < 3) { yield index++ } } var func = asyncFunc() var result while(result = func.next(), !result.done) { console.log(result.value) } //////////////////////////////// /////////async/await///////////// async function sleep(ms) { return new Promise((resolve) => { setTimeout(resolve, ms) }) } (async function() { console.log('Do some thing, ' + new Date()) await sleep(3000) console.log('Do other things, ' + new Date()) })() ////////////////////////////// //////////async/await//////////// function timeout(ms) { return new Promise((resolve) => { setTimeout(resolve, ms); }); } async function asyncPrint(value, ms) { console.log('before hello world') await timeout(ms); console.log(value) console.log('after hello world') } asyncPrint('hello world', 3000) //////////////////////////////
相关文章推荐
- Callback Promise Generator Async-Await 和异常处理的演进
- ES6总结--Promise 、Generator 、Async/Await
- 协程(Coroutine)-ES中关于Generator/async/await的学习思考
- Callback Promise Generator Async-Await 和异常处理的演进
- Callback Promise Generator Async-Await 和异常处理的演进_0
- 前端面试送命题(二)-callback,promise,generator,async-await
- Iterator、Generator、async、await 异步编程
- Callback Promise Generator Async-Await 和异常处理的演进_1
- node-使用promise, generator, async/await 读取文件的方法
- Callback Promise Generator Async-Await 和异常处理的演进_2
- 关于Promise,Generator,async / await 对异步的处理
- Generator与async/await与Generator的模拟
- Callback Promise Generator Async-Await 和异常处理的演进
- async/await 与 generator、co 的对比
- async 和 await 的异步处理
- Async/Await 异步编程中的最佳做法
- async 与 await 在 Web 下的应用
- .Net 4.5 的async 和await 的简单理解使用
- C#里的async和await
- [转]说说C#的async和await