Skip to content

Instantly share code, notes, and snippets.

@stvedt
Created February 17, 2017 19:19
Show Gist options
  • Save stvedt/a669d98c6a54c343bbd9ed14d900b5e2 to your computer and use it in GitHub Desktop.
Save stvedt/a669d98c6a54c343bbd9ed14d900b5e2 to your computer and use it in GitHub Desktop.
Thunks
//synchronous thunk
function add(x,y){
return x + y;
}
//wrapper to return a value
var thunk = function(){
return add(10,15);
}
thunk();
//Asynchronous thunks don't take any values but rather a callback
function addAsync(x,y,cb) {
setTimeout(function(){
return cb( x + y );
}, 1000);
}
var thunk = function(cb){
addAsync(10,15,cb);
}
thunk(function (sum){
console.log(sum);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment