parallel-ware
Execute middleware in parallel. For executing in series, see ware.
Example
The following example runs all the middleware in parallel.
var parallel = ; { return { calcsum += val; console; ; };} // executes in parallel, no order guarenteedvar middleware = ; middleware; // 2// 5// 6
Wait to Execute
You can also tell parallel-ware to wait to execute a middleware until a specific condition is met. The .when(wait, fn)
method takes the wait function as an optional first parameter.
var parallel = ; { return { calcsum += val; console; ; };} { return { ; };} var middleware = // executes after sum === 4 // executes after sum === 10, which never happens ; middleware; // 3// 4// 6
Managing Concurrency
You can limit the concurrency with which the middleware will get executed.
var middleware = ;
Monitoring Progress
And you can listen for progress events (following the same structure as visionmedia/batch progress events).
var middleware = ; middleware; middleware;
Error Handling
Middleware errors don't stop the overall execution, but are rather passed back in batch.
var parallel = ; { return { calcsum += val; ; };} { return { ; };} // executes in parallel, no order guarenteedvar middleware = ; middleware; // Error: 2 error(s) encountered.// [Error: Whale, Error: Porcupine]// 6
API
parallel()
Create a parallel middleware execution pipeline.
.use(fn)
Add a middleware fn
to the execution pipeline.
.when(wait, fn)
Add a middleware fn
to the execution pipeline to run after the wait
says it can.
The wait
function supports a synchronous signature:
{ return { return calcsum === val; };} var middleware = // executes after sum === 4 // executes after sum === 10, which never happens ; middleware;
And an asynchronous signature:
{ return { ; };} var middleware = // executes after sum === 4 // executes after sum === 10, which never happens ; middleware;
.concurrency(max)
Limit the amount of concurrently executing middleware to max
.
.on('progress', ..
Listen on progress events.
License
WWWWWW||WWWWWW
W W W||W W W
||
( OO )__________
/ | \
/o o| MIT \
\___/||_||__||_|| *
|| || || ||
_||_|| _||_||
(__|__|(__|__|