koa-async
A Node.js Koa wrapper for caolan/async.
Requirements
- Node.js v4.x+ for ES6 generators support
Usage
First, install the package using npm:
npm install koa-async --save
Then, require the koa-async
package and add the yield
keyword before each async
invocation, omitting the "done" callback function, as demonstrated here:
var async = ; // A sample list of items to processvar items = 1 2 3; // Example 1: Batch-processing items in parallel async; // Example 2: Filtering items in parallelvar filter = async; // The following will output [2]thisbody = result: filter ;
Koa Example
Here's a more complete example that includes creating a basic Koa app and using various async
methods (also available in examples/async.js
):
var async = ; // Create sample appvar app = ; // Sample middlewareapp; // HTTP portvar port = processenvPORT || 3000; // Listen for connectionsapp; // Log portconsole;
Run the script and visit http://localhost:3000/ to test it out. Check your Node.js console to see the test output.
License
Apache 2.0