Created
September 7, 2015 03:40
-
-
Save ironpeace/e7539aa9eb4515071025 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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