Skip to content

Instantly share code, notes, and snippets.

@heymichaelp
Created July 30, 2014 18:51
Show Gist options
  • Save heymichaelp/bd1db68f70c4bdbdeb5e to your computer and use it in GitHub Desktop.
Save heymichaelp/bd1db68f70c4bdbdeb5e to your computer and use it in GitHub Desktop.
function promisify( fnName, context, options ) {
/*jshint validthis:true */
var originalFn = context[ fnName ],
originalArity = originalFn.length;
if(arguments.length >= 2) // function( res, resolve[, reject]);
return originalFn;
return function() {
var deferred = Q.defer;
originalFn = _.partial( originalFn, _, deferred.resolve, deferred.reject );
originalFn.apply( context, arguments )
return deferred;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment