Releases: jwalton/js-promise-breaker
v7.0.0
A lot has changed in the world of javascript since promise-breaker v6. Async and promise based code is now the default instead of the other way around, and typescript has gained a lot of popularity.
promise-breaker v7 is a complete rewrite of promise-breaker, focusing on better typescript support, and simplified developer experience. Earlier versions of promise-breaker focused quite a bit on preserving the .length of a function, and frequently required passing in the expected number of parameters a function would require. v6 also required heavy usage of new Function as a result.
promise-breaker v7 renames make and break (which were always confusing names) to promisify and callbackify. promisify basically works the same way as node.js's util.promisify() but makes it so the provided function can be called
with a callback or will return a promise if one is not provided. Like util.promisify(), it works by taking the parameters passed in and adding a "promise callback" to the parameter list before passing it on to the underlying funciton. If the caller doesn't provide a callback, the promimse callback will be used by the underlying function causing the returned promise to eventually resolve or reject. If the caller does provide a callback, the promise callback will end up being ignored by the underlying function and the caller provided callback will be called instead. This works well in most cases, but can fall short for cases where the underlying function takes a variable number of parameters. For these cases, promise-breaker still provides addPromise and addCallback
functions which can be used to give you greater control.
Breaking Changes
- Rewrite.
makeandbreakare now aliases forpromisifyandcallbackify.promisifyno longer allows options as first argument.promisifyandcallbackifynow use a different algorithm which makes them simpler to use.- The
.lengthof functions generated bypromisifyandcallbackifyare no longer related to the function passed in. - This is now published only as an ESM library.