Skip to content

Instantly share code, notes, and snippets.

@robskillington
Created November 4, 2011 10:01
Show Gist options
  • Save robskillington/1339028 to your computer and use it in GitHub Desktop.
Save robskillington/1339028 to your computer and use it in GitHub Desktop.
callAsync playground
// Anonymize
(function () {
Function.prototype.callAsync = function () {
var self = this, args = arguments, result = {returned:false};
setTimeout(function () { result.returnVal = self.apply(self, args); result.returned = true; }, 0);
return result;
}
})();
var someResult;
console.debug((
someResult = function (a, b) {
var str = a + ': ' + b;
console.log(str);
return str;
}.callAsync('LogMsg', 'This message was run non-blockingly!')
));
// Watch output, someResult will assigned {returned:false} first
// Lazy way to test someResult gets updated
setTimeout(function () {
console.debug(someResult.returned);
console.debug(someResult.returnVal);
}, 10);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment