unpromisify
v0.2.0
Published
automatically adapt callbacks whether they are node style or promise returning
Downloads
6
Maintainers
Readme
unpromisify
automatically adapt callbacks whether they are node style or promise returning
usage
unpromisify(userCallback, ctx, args, done); unpromisify(userCallback, args, done); unpromisify(userCallback, done); unpromisify(userCallback, opts);
userCallback
: a user supplied callback that performs some async task. It may call a node style callback, or return a promise.done
oropts.done
: your callback, which will be called after user supplied async task completes.args
oropts.arg
: (optional) array of arguments to calluserCallback
with. A callback handler will automatically be appended as the last argument.ctx
oropts.ctx
: call the user supplied callback with this contextopts.syncResults
: by default, ifuserCallback
returns a non-promise, it is assumed that the return value is the intended result. This is similar toPromise.resolve(value)
orQ.when(value)
. To disable this feature, setopts.syncResults
tofalse
; non-promise return values will be ignored.
advantages
Allows you to write your code using standard node style callbacks, without forcing it on users who prefer to return promises.
Guarantees your callback will be called async. Preventing the release of Zalgo.
Guarantees your callback will only called once. A major benefit of promises is the guarantee that they can only be resolved once, and that your
then
handlers will only be called once. This prevents a common bug in node style callbacks where someone else's bad code might try to call your callback twice.unpromisify
provides the same "only resolve once" guarantee, regardless which method your user chooses.
releasing
Use the cut-release cli utility.
npm install -g cut-release
cut-release
follow the prompts