Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 6d8f7b4

Browse files
authored
Merge pull request #44 from jthoms1/master
fix(watch): Ensure that watch tasks are throttled to run one at a time per watcher.
2 parents a2d58d6 + 3d241df commit 6d8f7b4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/watch.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ export function startWatchers(context: BuildContext, options: BuildOptions, watc
2626

2727
watchConfig.watchers.forEach(watcher => {
2828
if (watcher.callback && watcher.paths) {
29+
let taskPromise = Promise.resolve();
30+
let nextTask = null;
2931
const watcherOptions = watcher.options || {};
3032
if (!watcherOptions.cwd) {
3133
watcherOptions.cwd = context.rootDir;
@@ -37,7 +39,11 @@ export function startWatchers(context: BuildContext, options: BuildOptions, watc
3739
const chokidarWatcher = chokidar.watch(paths, watcherOptions);
3840

3941
chokidarWatcher.on('all', (event: string, path: string) => {
40-
watcher.callback(event, path, context, options);
42+
nextTask = watcher.callback.bind(null, event, path, context, options);
43+
taskPromise.then(function() {
44+
taskPromise = nextTask();
45+
nextTask = null;
46+
});
4147
});
4248
}
4349
});

0 commit comments

Comments
 (0)