Skip to content

Instantly share code, notes, and snippets.

@SamanShafigh
Created July 19, 2018 03:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SamanShafigh/50e92228d94ed9b0e71dddae89e606e0 to your computer and use it in GitHub Desktop.
Save SamanShafigh/50e92228d94ed9b0e71dddae89e606e0 to your computer and use it in GitHub Desktop.
async using callback
// Async using call back
var addA = function (a, b, cb) {
setTimeout (() => {
cb(a + b);
}, 0);
};
// How to use it :D
addA(2, 3, (result) => {
console.log(result)
})
// Callback Hell :(
addA(1, 1, (r) => {
addA(r, 1, (r) => {
addA(r, 1, (r) => {
addA(r, 1, (r) => {
addA(r, 3, (r) => {
addA(r, 3, (r) => {
console.log(r)
})
})
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment