From 718102572a13d7e70d1f2c0b48b6b60a766b76b2 Mon Sep 17 00:00:00 2001 From: Greg Thornton Date: Wed, 17 Dec 2014 03:25:55 -0600 Subject: [PATCH] fix(watcher): Close file watchers on exit event --- lib/watcher.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/watcher.js b/lib/watcher.js index 9c55f6782..b58b840c0 100644 --- a/lib/watcher.js +++ b/lib/watcher.js @@ -73,7 +73,7 @@ var getWatchedPatterns = function(patternObjects) { }); }; -exports.watch = function(patterns, excludes, fileList, usePolling) { +exports.watch = function(patterns, excludes, fileList, usePolling, emitter) { var watchedPatterns = getWatchedPatterns(patterns); var options = { usePolling: usePolling, @@ -101,7 +101,13 @@ exports.watch = function(patterns, excludes, fileList, usePolling) { log.debug(e); }); + emitter.on('exit', function(done) { + chokidarWatcher.close(); + done(); + }); + return chokidarWatcher; }; -exports.watch.$inject = ['config.files', 'config.exclude', 'fileList', 'config.usePolling']; +exports.watch.$inject = ['config.files', 'config.exclude', 'fileList', 'config.usePolling', + 'emitter'];