Skip to content

Instantly share code, notes, and snippets.

@Kamisama666
Last active April 20, 2017 11:37
Show Gist options
  • Save Kamisama666/d807ebe4642f2a836c0d02e2769aa469 to your computer and use it in GitHub Desktop.
Save Kamisama666/d807ebe4642f2a836c0d02e2769aa469 to your computer and use it in GitHub Desktop.
Takes a native javascript promise and returns a Q promise
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