fundon

node v7 async await demo

  •  
  •   fundon · Oct 14, 2016 · 3081 views
    This topic created in 3526 days ago, the information mentioned may be changed or developed.
    5 replies    2016-10-14 10:15:12 +08:00
    doubleflower
        1
    doubleflower  
       Oct 14, 2016
    要分清哪些调用是异步的,哪些不是好容易出错,应该加个默认强制。
    haozes
        2
    haozes  
       Oct 14, 2016
    v7 还没发布吧
    fundon
        3
    fundon  
    OP
       Oct 14, 2016
    @doubleflower 很好分清呀,`async` `await` 关键字一目了然
    doubleflower
        4
    doubleflower  
       Oct 14, 2016
    @fundon 你有一大堆函数,在调用时你会分得清?除非你把每个 async 函数加上 async 前缀。

    比如

    xxx()
    await doThings()
    yyy()

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

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

    这个看人了,代码组织能力!要明确各个接口异步,同步情况。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4224 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 05:25 · PVG 13:25 · LAX 22:25 · JFK 01:25
    ♥ Do have faith in what you're doing.