Skip to content

Commit

Permalink
Merge pull request #14 from ElliotChong/feature/throttle
Browse files Browse the repository at this point in the history
Add --throttle option
  • Loading branch information
kimmobrunfeldt committed Oct 12, 2015
2 parents 1d644a3 + 609228b commit fc21687
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ Options:
surrounded with quotes when command contains spaces
-d, --debounce Debounce timeout in ms for executing command
[default: 400]
-t, --throttle Throttle timeout in ms for executing command
[default: 0]
-s, --follow-symlinks When not set, only the symlinks themselves will be
watched for changes instead of following the link
references and bubbling events through the links path
Expand Down
10 changes: 9 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var EVENT_DESCRIPTIONS = {

var defaultOpts = {
debounce: 400,
throttle: 0,
followSymlinks: false,
ignore: null,
polling: false,
Expand Down Expand Up @@ -55,6 +56,12 @@ var argv = require('yargs')
describe: 'Debounce timeout in ms for executing command',
type: 'number'
})
.option('t', {
alias: 'throttle',
default: defaultOpts.throttle,
describe: 'Throttle timeout in ms for executing command',
type: 'number'
})
.option('s', {
alias: 'follow-symlinks',
default: defaultOpts.followSymlinks,
Expand Down Expand Up @@ -131,7 +138,8 @@ function startWatching(opts) {
var chokidarOpts = createChokidarOpts(opts);
var watcher = chokidar.watch(opts.patterns, chokidarOpts);

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

Expand Down

0 comments on commit fc21687

Please sign in to comment.