Skip to content

Commit fc21687

Browse files
Merge pull request #14 from ElliotChong/feature/throttle
Add --throttle option
2 parents 1d644a3 + 609228b commit fc21687

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ Options:
8282
surrounded with quotes when command contains spaces
8383
-d, --debounce Debounce timeout in ms for executing command
8484
[default: 400]
85+
-t, --throttle Throttle timeout in ms for executing command
86+
[default: 0]
8587
-s, --follow-symlinks When not set, only the symlinks themselves will be
8688
watched for changes instead of following the link
8789
references and bubbling events through the links path

index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var EVENT_DESCRIPTIONS = {
1717

1818
var defaultOpts = {
1919
debounce: 400,
20+
throttle: 0,
2021
followSymlinks: false,
2122
ignore: null,
2223
polling: false,
@@ -55,6 +56,12 @@ var argv = require('yargs')
5556
describe: 'Debounce timeout in ms for executing command',
5657
type: 'number'
5758
})
59+
.option('t', {
60+
alias: 'throttle',
61+
default: defaultOpts.throttle,
62+
describe: 'Throttle timeout in ms for executing command',
63+
type: 'number'
64+
})
5865
.option('s', {
5966
alias: 'follow-symlinks',
6067
default: defaultOpts.followSymlinks,
@@ -131,7 +138,8 @@ function startWatching(opts) {
131138
var chokidarOpts = createChokidarOpts(opts);
132139
var watcher = chokidar.watch(opts.patterns, chokidarOpts);
133140

134-
var debouncedRun = _.debounce(run, opts.debounce);
141+
var throttledRun = _.throttle(run, opts.throttle);
142+
var debouncedRun = _.debounce(throttledRun, opts.debounce);
135143
watcher.on('all', function(event, path) {
136144
var description = EVENT_DESCRIPTIONS[event] + ':';
137145

0 commit comments

Comments
 (0)