node-async-flow
An aggressive async flow solution for node.js.
The support for Generator is required.
Why?
node.js is excellent for it's advanced support for new standards. But it's been a headache as there are callbacks everywhere and it's hard to compose logic between them.
Peoples have been attempting to solve this situation for a long time:
The async
provides handy utility functions to chain things together, along with a central error handing mechanism. It saves some nested callbacks but doesn't solve the problem.
There are also many Promise implementations, like q
and bluebird
. I personally dislike Promises because it's a standard which makes things harder: everything is in chainable callbacks and now we have a nice constructor and resolve and reject and then and catch, wow!
The co
is the widely used generator-based solution for the callback hells. It's similar to the async/await standard and use Promises. To be used with co
, everything should be Promises or "thunkified", which is another story.
Here comes the node-async-flow
.
Features
- No wrapper needed for existing code (compared to
new Promise
andthunkify
) - No need to pass variables every next step
- Async in native loops
- In place error handling (if error is solvable let's continue)
Installation
npm install node-async-flow --save
Examples
See examples, tests, nwjs-download and nwjs-builder :)
Some code snippets:
const exists readFile = ; const Flow = ; // Sleep 10 seconds.; // Async check file exists and do something.; // Async read file and parse JSON.
License
MIT.