Created
September 7, 2016 03:01
-
-
Save ZhihaoLau/63234273e85761fee12c0bf5a5968335 to your computer and use it in GitHub Desktop.
AsyncSum.js
This file contains hidden or 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
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