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

前端 未结 11 1715
执念已碎
执念已碎 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:53

    Yes there is, and you don't even need to compile it, because it is just a simple JavaScript library.

    One of my projects called sharpnr.js has the aim to extend JavaScript with great features of C# (and .NET of course) like await/async, or LINQ.

    The library is currently in beta, but it's stable and supports almost every statement (for example loops, switch, if), and works well with existing libraries (like jQuery).

    The await/async syntax is almost identical to the C# version:

    var getAsync = async(function(url) {
      var result = await; $.get(url);
      $("#test").html(result);
    });
    getAsync("http://www.sharpnrjs.com");
    

    Working example on jsfiddle.

    You can download the library from github.

提交回复
热议问题