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