Created
August 10, 2010 23:25
-
-
Save jonastemplestein/518221 to your computer and use it in GitHub Desktop.
Nifty function that generates a callback that cannot be executed synchronously
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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