A function to accept an argument mapping definition for a next step and return a callback.
async can be called many times, but all calls are done in same tick.
And all callbacks async returns must be called.

A function to accept a concurrency number and return another asyncEach function which
executes a provided function once per array element asynchronously with the specified cuncurrency.
If you use another asyncEach function directly, default concurrency 10 is used.

To pass asynchronous call results to a next function, arguments mapping definition is necessary.
The function as accepts an index to specify a callback argument and returns arguments mapping definition.
The function this.async accepts the mapping definition and return a callback.
When all callbacks are completed, the next function is called with specific arguments.

var flow =require('nue').flow;

var as =require('nue').as;

var fs =require('fs');

var myFlow = flow('myFlow')(

functionreadFiles(file1, file2){

fs.readFile(file1,'utf8',this.async(as(1)));

fs.readFile(file2,'utf8',this.async(as(1)));

},

functionend(data1, data2){

if(this.err)throwthis.err;

console.log(data1 + data2);// FILE1FILE2

console.log('done');

this.next();

}

);

myFlow('file1','file2');

Arguments mapping definition can contain arbitrary values.

var flow =require('nue').flow;

var as =require('nue').as;

var fs =require('fs');

var myFlow = flow('myFlow')(

functionreadFiles(file1, file2){

fs.readFile(file1,'utf8',this.async({name: file1, data: as(1)}));

fs.readFile(file2,'utf8',this.async({name: file2, data: as(1)}));

},

functionend(f1, f2){

if(this.err)throwthis.err;

console.log(f1.name+' and '+ f2.name+' have been read.');// file1 and file2 have been read.

In a last step in a flow, this.err represents an error which is thrown with throw, passed to this.endWith or passed to an async callback as first argument.
To indicate error handling is completed, you must assign null to this.err.