Async/await in web browser or in node.js?

前端 未结 11 1710
执念已碎
执念已碎 2020-12-29 23:18

Is there any attempt to bring async/await feature from C# 5.0 to any language which can be compiled to JavaScript (such as CoffeScript)? (So it can be used

11条回答
  •  醉梦人生
    2020-12-29 23:48

    I'm not familiar with C#, but it sounds like what you're looking for is some sort of continuations, so that instead of writing

    fs.readFile 'foo.txt', (err, data) ->
      myFunc data
    

    you could instead just write something like

    data = &fs.readFile 'foo.txt'  # not a real syntax
    myFunc data
    

    This isn't something that JavaScript or CoffeeScript provides. However, there are several other compilers that can do something like this:

    • TameJS - JavaScript-based, mainly just adds this feature
    • Kaffeine - JavaScript-based, adds a bunch of features
    • coco - CoffeeScript-based

    See also: List of languages that compile to JavaScript on the CoffeeScript wiki.

提交回复
热议问题