V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
fundon
V2EX  ›  分享发现

node v7 async await demo

  •  
  •   fundon · 2016-10-14 00:38:21 +08:00 · 2264 次点击
    这是一个创建于 2743 天前的主题,其中的信息可能已经有所发展或是发生改变。
    5 条回复    2016-10-14 10:15:12 +08:00
    doubleflower
        1
    doubleflower  
       2016-10-14 08:29:44 +08:00
    要分清哪些调用是异步的,哪些不是好容易出错,应该加个默认强制。
    haozes
        2
    haozes  
       2016-10-14 08:37:17 +08:00
    v7 还没发布吧
    fundon
        3
    fundon  
    OP
       2016-10-14 09:03:45 +08:00
    @doubleflower 很好分清呀,`async` `await` 关键字一目了然
    doubleflower
        4
    doubleflower  
       2016-10-14 09:14:21 +08:00
    @fundon 你有一大堆函数,在调用时你会分得清?除非你把每个 async 函数加上 async 前缀。

    比如

    xxx()
    await doThings()
    yyy()

    你忘了加 await 运行也不会报错,更搞的是不加 await 有时这段代码还能工作,太隐蔽的 BUG 啊。

    系统应该在调用 async 函数时不加 await 马上抛异常,或加上 nowait 标记,比如
    nowait doThing()
    fundon
        5
    fundon  
    OP
       2016-10-14 10:15:12 +08:00
    @doubleflower 不报错,这点没问题,一个 Promise 没加 await 也是能够正常运行的。

    这个看人了,代码组织能力!要明确各个接口异步,同步情况。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5971 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 02:32 · PVG 10:32 · LAX 19:32 · JFK 22:32
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.