Skip to content

Commit 28a70c4

Browse files
committed
Undo conflicting pull request paulmillr#690
1 parent 5261384 commit 28a70c4

1 file changed

Lines changed: 9 additions & 24 deletions

File tree

lib/nodefs-handler.js

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ var fs = require('fs');
44
var sysPath = require('path');
55
var readdirp = require('readdirp');
66
var isBinaryPath = require('is-binary-path');
7-
var debounce = require('lodash.debounce');
87

98
// fs.watch helpers
109

@@ -342,12 +341,15 @@ function(dir, stats, initialAdd, depth, target, wh, callback) {
342341
parentDir.add(sysPath.basename(dir));
343342
this._getWatchedDir(dir);
344343

345-
var debouncedRead;
346-
347344
var read = function(directory, initialAdd, done) {
348345
// Normalize the directory name on Windows
349346
directory = sysPath.join(directory, '');
350347

348+
if (!wh.hasGlob) {
349+
var throttler = this._throttle('readdir', directory, 1000);
350+
if (!throttler) return;
351+
}
352+
351353
var previous = this._getWatchedDir(wh.path);
352354
var current = [];
353355

@@ -378,11 +380,9 @@ function(dir, stats, initialAdd, depth, target, wh, callback) {
378380
this._addToNodeFs(path, initialAdd, wh, depth + 1);
379381
}
380382
}.bind(this)).on('end', function() {
383+
if (throttler) throttler.clear();
381384
if (done) done();
382385

383-
// Run any pending reads that may be queued
384-
debouncedRead.flush();
385-
386386
// Files that absent in current directory snapshot
387387
// but present in previous emit `remove` event
388388
// and are removed from @watched[directory].
@@ -401,35 +401,20 @@ function(dir, stats, initialAdd, depth, target, wh, callback) {
401401
}.bind(this)).on('error', this._handleError.bind(this));
402402
}.bind(this);
403403

404-
// Create a debounced version of read
405-
debouncedRead = debounce(read, 1000, {
406-
leading: true,
407-
trailing: true,
408-
maxWait: 1000
409-
});
410-
411404
var closer;
412405

413406
if (this.options.depth == null || depth <= this.options.depth) {
414407
if (!target) read(dir, initialAdd, callback);
415408
closer = this._watchWithNodeFs(dir, function(dirPath, stats) {
416409
// if current directory is removed, do nothing
417410
if (stats && stats.mtime.getTime() === 0) return;
418-
debouncedRead(dirPath, false);
411+
412+
read(dirPath, false);
419413
});
420414
} else {
421415
callback();
422416
}
423-
424-
// Close function that calls fs closer and cancels any pending debounced reads
425-
return function () {
426-
if (closer) {
427-
closer();
428-
}
429-
430-
// Cancel any pending reads that may be queued
431-
debouncedRead.cancel();
432-
};
417+
return closer;
433418
};
434419

435420
// Private method: Handle added file, directory, or glob pattern.

0 commit comments

Comments
 (0)