Last active
April 20, 2017 11:37
-
-
Save Kamisama666/d807ebe4642f2a836c0d02e2769aa469 to your computer and use it in GitHub Desktop.
Takes a native javascript promise and returns a Q promise
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
const Q = require('q'); | |
/** | |
* Transforms a Promise to a Q promise | |
* @param {Promise} promise | |
* @return {Q} | |
*/ | |
function pq(promise) { | |
const deferred = Q.defer(); | |
promise | |
.then(function(result) { | |
deferred.resolve(result); | |
}) | |
.catch(function(error) { | |
deferred.reject(error) | |
}) | |
return deferred.promise; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment