Skip to content

Instantly share code, notes, and snippets.

@tuchida
Created October 30, 2012 15:36
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuchida/3980999 to your computer and use it in GitHub Desktop.
Save tuchida/3980999 to your computer and use it in GitHub Desktop.
async/await in sweet.js
macro async {
case :{ $rest } => {
$rest
}
case :{ $head $rest ... } => {
$head
async: { $rest ... }
}
case :{ var $x:ident = await($yield:ident, $y ...); $rest ... } => {
(function($yield) {
$y ...;
}).call(this, function($x) {
async: { $rest ... }
}.bind(this));
}
}
async: {
var x = await(yield_, setTimeout(function() { yield_(123); }, 1000));
console.log(x);
var y = await(yield_, setTimeout(function() { yield_(x+x); }, 2000));
console.log(y);
}
// (function (yield_$1) {
// setTimeout(function () {
// yield_$1(123);
// }, 1000);
// }.call(this, function (x$4) {
// console.log(x$4);
// (function (yield_$12) {
// setTimeout(function () {
// yield_$12(x$4 + x$4);
// }, 2000);
// }.call(this, function (y$15) {
// console.log(y$15);
// }.bind(this)));
// }.bind(this)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment