Pipe Callbacks
This little function will allow you to pipe callback functions. The function takes as many callback functions as you want to pipe and then an error (reject) function and a resolve function. If you don't at least pass three functions it will error.
I like callbacks vs promises as many mess up promises anyways. This is a nice function to avoid callback hell and make it easy to read. It also forces you to handle the error and resolve correctly.
We read far more code then we write and this makes a bunch of callback functions easy to read and reason about.
Install
To install this function in your project run
npm install pipe-callback
Usage
The callback functions you can pipe take a single value and then the callback, the normal javascript style.
{ // ... Do work and then call cb}
If the first callback in the list needs a value then you need to make it the first thing you pass to the pipe-callbacks function.
const pipeCallbacks = ; { ;} ; // Logs: StartDataMoreMoreMore
You can also start with a callback that takes no value.
const pipeCallbacks = ; { ;} { ;} ; // Logs: GetDataMoreMoreMore
If any of your callbacks error the second to last function is called right away with the error.
const pipeCallbacks = ; { ;} { ;} { ;} ; // Errors: getMoreData error
Improvements
If you have any improvements please feel free to open an issue or pull request.
Enjoy!