Skip to content

Instantly share code, notes, and snippets.

@jonastemplestein
Created August 10, 2010 23:25
Show Gist options
  • Save jonastemplestein/518221 to your computer and use it in GitHub Desktop.
Save jonastemplestein/518221 to your computer and use it in GitHub Desktop.
Nifty function that generates a callback that cannot be executed synchronously
/**
* Nifty function that generates a callback that cannot be executed synchronously
* This is useful to circumvent the behaviour of crappy libraries that are not always async
* (e.g. if they cache certain results)
*/
exports.callAsync = function(original_callback) {
// capture scope
var self = this;
return function() {
var args = arguments;
process.nextTick(function(){
original_callback.apply(self, args);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment