- aggregateFn(fn, options) ⇒
aggregateFnReturnedObject
Creates a wrapper of the provided function that enables aggregation capabilities
- aggregateFnReturnedObject
- statsCb :
function
aggregateFn(fn, options) ⇒ aggregateFnReturnedObject
Creates a wrapper of the provided function that enables aggregation capabilities
Kind: global function
Param | Type | Default | Description |
---|---|---|---|
fn | function |
Async function that has to be wrapped (usually a bulk function) | |
options | object |
Configuration | |
options.maxWaitTime | number |
1000 |
Max delay that can be introduced (calculated on the older item in queue ) |
options.maxItems | number |
100 |
Max number of items that can be aggregated together |
options.stats | statsCb |
Callback called every time that a requested is served. |
Example
import { aggregateFn } from 'aggregateFn'
const { fn, flush, cancel } = aggregateFn( myAggregableAsyncFn, {
maxWaitTime: 200,
maxItems: 2,
stats: console.log
})
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
fn | function |
Wrapped version of the provided function |
flush | function |
A function that forces to call immediately the original function regardless of maxWaitTime and maxItems configuration |
cancel | function |
A function that cancels any pending request (by the way it rejects any pending promise) |
Kind: global typedef
Param | Type | Description |
---|---|---|
ok | boolean |
Indicates if last execution has been completed with success |
count | number |
Number of aggregated items |
swarf | number |
Indicates the wasted aggregation (maxItems - count) |
delay | number |
Delay introduced to the first queued item |