Skip to content

Instantly share code, notes, and snippets.

@organom
Created February 26, 2019 15:27
Show Gist options
  • Save organom/3d82c2c6f89e07c3675faf02a9f7327b to your computer and use it in GitHub Desktop.
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
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