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

fix(watch): Ensure that watch tasks are throttled to run one at a time per watcher. #44

Merged
merged 1 commit into from
Sep 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export function startWatchers(context: BuildContext, options: BuildOptions, watc

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

chokidarWatcher.on('all', (event: string, path: string) => {
watcher.callback(event, path, context, options);
nextTask = watcher.callback.bind(null, event, path, context, options);
taskPromise.then(function() {
taskPromise = nextTask();
nextTask = null;
});
});
}
});
Expand Down