-
-
Save scottcorgan/4331467 to your computer and use it in GitHub Desktop.
Function wrapper to avoid creating a new deferred in every function using the Q (http://documentup.com/kriskowal/q) library.
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
/* | |
Function wrapper to avoid creating a new deferred in every function | |
using the Q (http://documentup.com/kriskowal/q) library. | |
*/ | |
// Wrapper Function | |
function _q (callback) { | |
return function () { | |
var deferred = Q.defer(), | |
args = [].slice.call(arguments, 0); | |
args.unshift(deferred); | |
callback.apply(null, args); | |
return deferred.promise; | |
} | |
}; | |
// Usage | |
var foo = _q(function (_d, arg1, arg2) { | |
console.log('called function foo'); | |
_d.resolve('foo resolved'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment