Skip to content

Instantly share code, notes, and snippets.

@yankov
Created June 26, 2012 23:51
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 yankov/3000252 to your computer and use it in GitHub Desktop.
Save yankov/3000252 to your computer and use it in GitHub Desktop.
js pattern for async calls
var future = function(d) {
var obj = {};
obj.val = 0;
setTimeout(function(){ obj.val=d;}, 5000);
return obj;
}
var result = future(4);
console.log(result.val) // returns 0
// after 5 seconds
console.log(result.val) // returns 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment