You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This fill work fine, until you change multiple files with some git command - watch will call mocha as many times, as many files was changed. And this is perfectly fine, because this is how gulp should work.
But this is definitely a problem - most of the grunt related blog posts are about - "How to rebuild your css/jade/etc on edit". So I see a way in writing gulp plugin throttle (or something, I can't figure proper name) that will buffer incoming events (for 5 seconds then flush) and call callback only once:
What you're asking for is a debounce. This seems like a common enough use case that it should probably be baked into the watcher itself rather than the client wrapping the callback.
This falls somewhere between glob-watcher and gaze, since gaze (correctly) debounces changes to single files and glob-watcher (also correctly) passes all changed files. Probably best to throw the debounce on glob-watcher line 8, yeah?
I'd open a pull but the tests are currently broken.
@akre54: This is neither a throttle or debounce. I think of this more as throttle + debounce + group.
@sindresorhus: Maybe in gulp utils, but not into watch or other methods should implement it too?
@contra: In my opinion this is not work for gaze at all. I agreed with @akre54 - this is something in between, but watch and gulp plugin (or it depends on task you want to achieve).
@akre54 glob-watcher just passes what gaze puts out. If gaze was debouncing the files before putting it out then this wouldn't be a problem. I scanned the gaze repo for "debounce" and "throttle" and didn't get any hits. Where do you see that it's debouncing?
That is, wouldn't it be better to "batch" watched files, so as to not spam the CLI of some app? Batch 20 files at a time, then 'flush' on timeout (2s) which handles outstanding batches.
Thanks guys! I think gulp-batch is finished, so my problem is fixed. Thou it will be nice to mention it in API docs (I think many people will stumble upon this, when will try to test their code with mocha and watch).
Activity
akre54 commentedon Jan 2, 2014
What you're asking for is a
debounce. This seems like a common enough use case that it should probably be baked into the watcher itself rather than the client wrapping the callback.sindresorhus commentedon Jan 2, 2014
Yeah, should be baked in IMHO.
yocontra commentedon Jan 2, 2014
Gaze is the gulp file watcher https://github.com/shama/gaze/issues
akre54 commentedon Jan 2, 2014
This falls somewhere between glob-watcher and gaze, since gaze (correctly) debounces changes to single files and glob-watcher (also correctly) passes all changed files. Probably best to throw the debounce on glob-watcher line 8, yeah?
I'd open a pull but the tests are currently broken.
floatdrop commentedon Jan 2, 2014
@akre54: This is neither a
throttleordebounce. I think of this more asthrottle+debounce+group.@sindresorhus: Maybe in gulp utils, but not into
watchor other methods should implement it too?@contra: In my opinion this is not work for
gazeat all. I agreed with @akre54 - this is something in between, butwatchand gulp plugin (or it depends on task you want to achieve).yocontra commentedon Jan 2, 2014
@akre54 glob-watcher just passes what gaze puts out. If gaze was debouncing the files before putting it out then this wouldn't be a problem. I scanned the gaze repo for "debounce" and "throttle" and didn't get any hits. Where do you see that it's debouncing?
akre54 commentedon Jan 2, 2014
@contra gaze#L84-L85 gaze#L118-L120
yocontra commentedon Jan 2, 2014
@akre54 sweet - @floatdrop just sent a PR to let those options go through gulpjs/glob-watcher#2
floatdrop commentedon Jan 2, 2014
These options are cool, but don't solve this problem.
dashed commentedon Jan 2, 2014
Instead of waiting for some arbitrary time to collect files to flush, would it be better to use some sort of queue? See https://github.com/caolan/async#queueworker-concurrency.
That is, wouldn't it be better to "batch" watched files, so as to not spam the CLI of some app? Batch 20 files at a time, then 'flush' on timeout (2s) which handles outstanding batches.
You can queue via gulp.watch's event variable.
yocontra commentedon Jan 2, 2014
I'll take PRs for this in glob-watcher but won't have time to implement anything until the 10th
dashed commentedon Jan 2, 2014
This seemed to be an interesting problem. I took a crack at it. @floatdrop would the following work for you? I haven't really tested it.
floatdrop commentedon Jan 3, 2014
@dashed yep, that looks like what I wanted. I started working on gulp-batch right before read this.
dashed commentedon Jan 3, 2014
That looks really cool. I hadn't thought of using the function decorator pattern.
Much better and simpler than mine.
floatdrop commentedon Jan 3, 2014
Thanks guys! I think gulp-batch is finished, so my problem is fixed. Thou it will be nice to mention it in API docs (I think many people will stumble upon this, when will try to test their code with
mochaandwatch).sindresorhus commentedon Jan 3, 2014
@floatdrop nice work. use the
gulpfriendlykeyword instead ofgulpplugin.