tiddlywiki-plugin-dev
Version:
[](https://github.com/tiddly-gittly)
32 lines (31 loc) • 634 B
JavaScript
const createQueuedWatchHandler = ({
runBatch,
onError
}) => {
let pendingPaths;
return async (changedPath) => {
if (pendingPaths !== void 0) {
if (changedPath) {
pendingPaths.push(changedPath);
}
return;
}
pendingPaths = changedPath ? [changedPath] : [];
while (true) {
const batch = pendingPaths;
pendingPaths = [];
try {
await runBatch(batch);
} catch (error) {
onError?.(error, batch);
}
if (pendingPaths.length === 0) {
pendingPaths = void 0;
return;
}
}
};
};
export {
createQueuedWatchHandler
};