1. let co = require("co");
  2. //模拟异步操作
  3. let wait = (t) => {
  4. return new Promise((resolve, reject) => {
  5. console.log("start:" + t);
  6. setTimeout(() => {
  7. console.log(t);
  8. resolve();
  9. }, t);
  10. })
  11. }
  12. //co库的用法
  13. co(function* () {
  14. let p = yield [wait(500), wait(200), wait(2000)];
  15. console.log("finish");
  16. })
  17. //原生async/await的用法
  18. let app = async () => {
  19. let p = await Promise.all([wait(500), wait(200), wait(2000)]);
  20. console.log("finish");
  21. }
  22. app();






相关文章:

  • 2021-08-17
  • 2022-12-23
  • 2021-12-29
  • 2022-03-06
  • 2022-12-23
  • 2021-11-24
  • 2021-08-31
  • 2022-12-23
猜你喜欢
  • 2021-09-09
  • 2021-12-28
  • 2022-12-23
  • 2021-08-13
  • 2021-10-29
  • 2021-06-20
相关资源
相似解决方案