with-callback
A small helper function to bridge the gap when returning a promise from a function that takes a callback
Note that this module will not introduce any custom Promise implementation.
It will use the global Promise
(requires node >= v4).
import withCallback from 'with-callback';
function readFile(name) {
return withCallback(callback => fs.readFile(name, callback));
}
function readFile(name) {
return withCallback([name], fs.readFile);
}
function example(callback) {
callback(null, 'a', 'b');
}
const promise = withCallback(example, (a, b) => [a, b]);