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

前端 未结 11 1762
执念已碎
执念已碎 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-30 00:08

    Async is on feature list for JavaScript harmony. So far there are numerous attempts to provide such functionality in the browser or in node, none of them seem to be compatible with harmony proposal though:

    • Async can be simulated with JS1.7 generators (see task.js). Not yet supported out-of-the-box by V8 (without experimental mode), but works in FF. Possibly traceur or Masacra compiler can be used to bring generators to other environments.
    • There is node-fibers library providing other mechanism for asynchronous programming in node (scarifies performance though). Other attempt basing on v8cgi is described here.
    • Rhino has continuations out of the box providing good alternative. This is why Ringo.js might be worth looking at.
    • Few solutions basing on js2js translation are available, e.g: jscx, NarrativeJS, jwacs, StratifiedJS. Some support integration with node.
    • There are many promise/future libraries trying to solve callbacks problem without extending syntax, however they all suffer from composability issues, i.e. cannot use language constructs like loops across callbacks.

提交回复
热议问题