A Koa wrapper for caolan/async.
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 parallelasync;// Example 2: Filtering items in parallelvar filter = async;// The following will output thisbody = result: filter ;
Here's a more complete example that includes creating a basic Koa app and using various
async methods (also available in
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.