Skip to content

Instantly share code, notes, and snippets.

@Enelar
Created April 13, 2020 10:58
Show Gist options
  • Save Enelar/adc620f262a0cdb00f45f7b50eb0b09d to your computer and use it in GitHub Desktop.
Save Enelar/adc620f262a0cdb00f45f7b50eb0b09d to your computer and use it in GitHub Desktop.
Quick to promise method
to_direct_promise(functor, ...args) {
return this.to_promise(functor, ...args, undefined);
}
to_promise(functor, ...args) {
const options = args.pop();
let resolve;
let reject;
const result = new Promise((res, cat) => {
resolve = res;
reject = cat;
});
functor.call(this, ...args, (error, data) => {
if (error) {
return reject(error);
}
return resolve(data);
}, options);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment