sweet-es7-async

0.0.0 • Public • Published

sweet-es7-promise

Build Status

A sweet.js macro for ES7 async functions.

You're probably better off using the Traceur Compiler, but this is a fun experiment.

Usage

var getComments = async function (postId) {
    var response = await fetch("/posts/" + postId);
 
    if ( response.headers["X-Has-No-Comments"] ) {
        return;
    }
 
    var post = await response.body.to("json");
    return post.comments;
};

Translates to:

var getComments = function (postId) {
    return Promise.resolve().then(function () {
        return fetch("/posts/" + postId).then(function (response) {
            if ( response.headers["X-Has-No-Comments"] ) {
                return;
            }
 
            return response.body.to("json").then(function (post) {
                return post.comments;
            });
        });
    });
};

Missing features

  • try-catch blocks with await.

Package Sidebar

Install

npm i sweet-es7-async

Weekly Downloads

0

Version

0.0.0

License

MIT

Last publish

Collaborators

  • jussi-kalliokoski