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
{{ message }}
Repository navigation
gulp.watch(glob, cb) and gulp.watch(glob).pipe(...) #84
This is why gulp-batch exists - if you change multiple files these guys 'lint', 'sass', 'scripts' will be runned multiple times.
If you look at gulp api - all methods should support streaming, but grunt.watch not. I think this is a source of confusion. If it can be refactored into stream, then it will be clearer (a little) that it will emit file by file like src does.
But there is another problem with watch - people often want do not what it does. Now "watch is getting changed file and calls callback on each". What often needed - is "if any of this files changed - rerun task. Once. And be aware of multiple files can change at once".
As you can see, even if we batched incoming files, we can assure, that grunt.run will be called separately and not interfere with already running one. (or I miss something in streams - may be hacks on backpressure?)
So I propose make callback version of watch batching by default and streaming version - is just streaming version.
Well, after looking at articles on gulp I think, baking in batching in watch is a solution of many problems, that are already floated up. I predict many copy-pasted watch code from mentioned article, that potentially broken.
Your API scenario is bad, because you introducing duplicate behaviour (by default, but still) - so what the point? Here is my version:
gulp.watch(glob [, opts], cb) - are batching by default (by the way - opts already there), but can be tuned with opts
gulp.watch(glob [, batch_opts]) - return stream without batch'ness.
P.s. batchness to stream can be added with using .pipe so no need to include it.
I hadn't meant batch_opts to be specifically for batching; more of gulp.watch options.
What would be a good value for the hypothetical opts.batch.limit for scenario 1 other than opts.batch.limit = 1? Isn't it batching in all values of opts.batch.limit anyways?
I made my API scenario (in particular scenario 1) to be compatible with current behaviour.
If the callback version of gulp.watch has batching, there should be no reason its streaming counterpart shouldn't.
But I just realized scenario 2 seems to be weird. What if we break it down to see what it should do (from what I understand). Assume given streaming gulp.watch with batch:
Collect event(s) for batching according to batch rules.
Drain collected event(s).
Collect any new event(s) as new batch; but don't drain yet. A listener could be hooked via .on('end') to count events. Drain when count satisfy batch rules (make sure to drain accordingly when it overflows). Repeat step 3.
This requires something like { end: false }.
I think, as in the 3rd snippet, you suggested some magic function to collect all the batched events down the stream? I'm unsure how to do that :)
So gulp-watch is in alpha-ready version. It implements API that I described at the issue. You can see its readme section for information.
@contra re-emitting glob is rare case. I thing watching will be on all source files + test files and mocha must get only test files.
As @contra sayd in IRC - the best route to get stuff in is to just make it in userland, work out the bugs there, then if it seems like the right fit we can pull it into core - so more versions of watch api implemented in plugins will be awesome.
Activity
floatdrop commentedon Jan 3, 2014
This is a way of solving #76
dashed commentedon Jan 3, 2014
Wouldn't the last snippet
be better as
?
IMO, the first and last snippets seem to be anti-patterns and no one should use
gulp.runin that manner for the problems you've just described.If batching were to be baked into gulp.watch, wouldn't batch limit of 1 make gulp.watch behave as it is currently implemented?
Assuming #13 is done, the revised API could be:
gulp.watch(glob [[, batch_opts], cb])API scenario:
gulp.watch(glob [, batch_opts], cb)- events are deferred to callback with optional batch'ness. Doesn't return stream.gulp.watch(glob [, batch_opts])- assumed to be streaming, also with optional batch'ness. Does return stream.In all scenarios,
batch_opts.limit = 1by default.floatdrop commentedon Jan 3, 2014
Well, after looking at articles on gulp I think, baking in batching in watch is a solution of many problems, that are already floated up. I predict many copy-pasted watch code from mentioned article, that potentially broken.
Your API scenario is bad, because you introducing duplicate behaviour (by default, but still) - so what the point? Here is my version:
gulp.watch(glob [, opts], cb)- are batching by default (by the way -optsalready there), but can be tuned withoptsgulp.watch(glob [, batch_opts])- return stream without batch'ness.P.s. batchness to stream can be added with using
.pipeso no need to include it.dashed commentedon Jan 3, 2014
I hadn't meant
batch_optsto be specifically for batching; more of gulp.watch options.What would be a good value for the hypothetical
opts.batch.limitfor scenario 1 other thanopts.batch.limit = 1? Isn't it batching in all values ofopts.batch.limitanyways?I made my API scenario (in particular scenario 1) to be compatible with current behaviour.
If the callback version of gulp.watch has batching, there should be no reason its streaming counterpart shouldn't.
But I just realized scenario 2 seems to be weird. What if we break it down to see what it should do (from what I understand). Assume given streaming gulp.watch with batch:
Collect event(s) for batching according to batch rules.
Drain collected event(s).
Collect any new event(s) as new batch; but don't drain yet. A listener could be hooked via
.on('end')to count events. Drain when count satisfy batch rules (make sure to drain accordingly when it overflows). Repeat step 3.This requires something like
{ end: false }.I think, as in the 3rd snippet, you suggested some magic function to collect all the batched events down the stream? I'm unsure how to do that :)
yocontra commentedon Jan 3, 2014
This conversation is about
There are already a few open issues regarding these. Should I close everything and consolidate it somewhere?
dashed commentedon Jan 3, 2014
Good point. Feel free to close/reference as you see fit.
yocontra commentedon Jan 3, 2014
Also please note complexities with watch streams are
yocontra commentedon Jan 4, 2014
Possible solution to the "needs all the files" problem
dashed commentedon Jan 4, 2014
That could work.
floatdrop commentedon Jan 4, 2014
So gulp-watch is in alpha-ready version. It implements API that I described at the issue. You can see its readme section for information.
@contra re-emitting glob is rare case. I thing watching will be on all source files + test files and mocha must get only test files.
As @contra sayd in IRC -
the best route to get stuff in is to just make it in userland, work out the bugs there, then if it seems like the right fit we can pull it into core- so more versions of watch api implemented in plugins will be awesome.yocontra commentedon Jan 4, 2014
Nice job @floatdrop