Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jayphelps/sweet-async-await
Sweet.js macros to support the async/await ES7 proposed feature
https://github.com/jayphelps/sweet-async-await
Last synced: 16 days ago
JSON representation
Sweet.js macros to support the async/await ES7 proposed feature
- Host: GitHub
- URL: https://github.com/jayphelps/sweet-async-await
- Owner: jayphelps
- License: mit
- Created: 2014-05-30T00:21:02.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-07-31T18:16:50.000Z (over 10 years ago)
- Last Synced: 2024-12-31T14:14:39.434Z (26 days ago)
- Language: JavaScript
- Size: 258 KB
- Stars: 36
- Watchers: 4
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
sweet-async-await
=================[Sweet.js](http://sweetjs.org/) macros to support the async/await [ES7 proposed feature](https://github.com/lukehoban/ecmascript-asyncawait) for handling JavaScript [Promises](https://www.promisejs.org/)
***Probably incomplete and broken. Consider this an experiment at this point***
##### Input
```javascript
async function findPosts() {
var response = await $.get('/posts');
return JSON.parse(response.posts);
}async function main() {
console.log('starting...');
var posts = await findPosts();posts.forEach(function (post) {
console.log(post);
});
console.log('ending...');
}main();
```
##### Output
```javascript
function findPosts() {
var ctx = this, args = arguments;
return Promise.resolve().then(function () {
var response;
return $.get('/posts').then(function (value) {
response = value;
return JSON.parse(response.posts);
});
});
}function main() {
var ctx = this, args = arguments;
return Promise.resolve().then(function () {
console.log('starting...');
var posts;
return findPosts().then(function (value) {
posts = value;
posts.forEach(function (post) {
console.log(post);
});
console.log('ending...');
});
});
}main();
```
### Goals
The primary end-goal is to output the same human readable code you would use if this didn't exist, instead of using a state machine like the [traceur-compiler](https://github.com/google/traceur-compiler) does; which is far less intuitive for debugging promise chains. Also, unlike traceur, there is **no runtime** library required. (unless you need to provide a Promise polyfill)