Created
February 26, 2019 15:27
-
-
Save organom/3d82c2c6f89e07c3675faf02a9f7327b to your computer and use it in GitHub Desktop.
Callback to promise with adapter - easiest way to convert a function that relies on a callback that is not the last argument
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
const util = require('util'); | |
postRequest(url, postData, cb, authToken, retries, inOptions) { (...) } | |
postRequestAsync(url, postData, authToken, retries, inOptions) { | |
const adapter = (url, postData, authToken, retries, inOptions, cb) => { | |
this.postRequest(url, postData, cb, authToken, retries, inOptions); | |
}; | |
return util.promisify(adapter)(url, postData, authToken, retries, inOptions); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment