util.callbackify
A backport of util.callbackify
for Node.js 6.0 and up.
Installation
npm install --save util-callbackify
Usage
const callbackify = { return 'Hello, World!'} const callbackFunction =
API
callbackify(original)
original
<Function> Anasync
function- Returns: <Function> a callback style function
Takes an async
function (or a function that returns a Promise
) and returns a
function following the error-first callback style, i.e. taking
an (err, value) => ...
callback as the last argument. In the callback, the
first argument will be the rejection reason (or null
if the Promise
resolved), and the second argument will be the resolved value.
The callback is executed asynchronously, and will have a limited stack trace.
If the callback throws, the process will emit an 'uncaughtException'
event, and if not handled will exit.
Since null
has a special meaning as the first argument to a callback, if a
wrapped function rejects a Promise
with a falsy value as a reason, the value
is wrapped in an Error
with the original value stored in a field named
reason
.
{ return Promise}const callbackFunction = util