Skip to content

Instantly share code, notes, and snippets.

@zlatkov
Created October 11, 2017 14:39
Show Gist options
  • Save zlatkov/1ffa6e00a2750217f1a168fe36deda08 to your computer and use it in GitHub Desktop.
Save zlatkov/1ffa6e00a2750217f1a168fe36deda08 to your computer and use it in GitHub Desktop.
function sum(getX, getY, callback) {
var x, y;
getX(function(result) {
x = result;
if (y !== undefined) {
callback(x + y);
}
});
getY(function(result) {
y = result;
if (x !== undefined) {
callback(x + y);
}
});
}
// A sync or async function that retrieves the value of `x`
function fetchX() {
// ..
}
// A sync or async function that retrieves the value of `y`
function fetchY() {
// ..
}
sum(fetchX, fetchY, function(result) {
console.log(result);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment