Skip to content

Instantly share code, notes, and snippets.

@ironpeace
Created September 7, 2015 03:40
Show Gist options
  • Save ironpeace/e7539aa9eb4515071025 to your computer and use it in GitHub Desktop.
Save ironpeace/e7539aa9eb4515071025 to your computer and use it in GitHub Desktop.
// ES5
$.get("/aj1", function(data1){
$.get("/aj2?arg=" + data1, function(data2){
console.log(data2);
});
});
//ES6
function async(genertorFactory) {
var generator = genertorFactory.apply(this, arguments);
var handleResult = function(result) {
if(result.done) return result.value;
return result.value.then(function(nextResult) {
return handleResult(generator.next(nextResult));
}, function(error) {
generator.throw(error);
})
};
return handleResult(generator.next());
}
async(function* main(){
var data1 = yield $.get("/aj1");
var data2 = yield $.get("/aj2?arg=" + data1);
console.log(data2);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment