sweet-es7-async
v0.0.0
Published
A sweet.js macro for ES7 async functions.
Downloads
2
Maintainers
Readme
sweet-es7-promise
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.