Skip to content

Instantly share code, notes, and snippets.

@ZhihaoLau
Created September 7, 2016 03:01
Show Gist options
  • Save ZhihaoLau/63234273e85761fee12c0bf5a5968335 to your computer and use it in GitHub Desktop.
Save ZhihaoLau/63234273e85761fee12c0bf5a5968335 to your computer and use it in GitHub Desktop.
AsyncSum.js
function add(getX, getY, cb) {
var x, y;
getX(function(xVal) {
x = xVal;
if (y !== undefined) {
cb(x + y);
}
});
get(function(yVal) {
y = yVal;
if (x !== undefined) {
cb(x + y);
}
});
}
add(fetchX, fetchY, function(sum) {
console.log(x + y);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment