UNPKG

tiddlywiki-plugin-dev

Version:

[![](https://img.shields.io/badge/Join-TiddlyWiki_CN-blue)](https://github.com/tiddly-gittly)

32 lines (31 loc) 634 B
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 };