Aggregates add
, change
and unlink
file events that happen while some async
action is in progress.
aggregate(eventEmitter, callback, [setup])
Where:
eventEmitter
- is anything which emitsadd
,change
andunlink
events with optionalStat
object as event payloadcallback
- will be called with minimal set of changes that describe what happened since last call. This function can return aPromise
to delay subsequent calls until completitionsetup
- will be called just after initialization. This function can return aPromise
to delaycallback
calls until completition
const { aggregate } = require('agg-watcher')
aggregate(chokidar, async ({ added, changed, unlinked }) => {
// this fn won't be called again until current invocation completes
const all = [...added, ...changed, ...unlinked]
for (const [path, maybeStat] of all) {
console.log(path, maybeStat && maybeStat.mtime)
}
await doSomethingAsync(added, changed, unlinked)
})