work-batcher
Module to handle batching/aggregation of work with a timeout. E.g. batching requests to an API where you can stuff the payload will multiple queries.
You need to provide a worker. When either the timeout expires or we have enough items, the worker will be called. A function to multiplex the results together for the worker should be provided, as well as a function to demultiplex the results in the response.
Usage
var Batch = async = expect = ; var batch = // Will assemble the individual payloads into one payload for the worker when // it is time to call it. { return items; } // Will dis-assemble the result into individual results when the worker gives // us a result. { return resultindex; } // The worker to call. called when we have maxItems or timeout occurs. { var result = {}; data; ; } maxItems: 3 timeout: 500; /** * Simple example involving a worker function that returns the squares of each * element in the array. */async;