unpromisify v0.2.0
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.doneoropts.done: your callback, which will be called after user supplied async task completes.argsoropts.arg: (optional) array of arguments to calluserCallbackwith. A callback handler will automatically be appended as the last argument.ctxoropts.ctx: call the user supplied callback with this contextopts.syncResults: by default, ifuserCallbackreturns 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.syncResultstofalse; 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
thenhandlers 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.unpromisifyprovides the same "only resolve once" guarantee, regardless which method your user chooses.
releasing
Use the cut-release cli utility.
npm install -g cut-releasecut-releasefollow the prompts
