Created
December 18, 2012 20:07
-
-
Save anonymous/4331459 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 hidden or 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
/** 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