Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gulp.watch: running the same tasks over each other #557

Closed
avp opened this issue Jun 28, 2014 · 13 comments
Closed

gulp.watch: running the same tasks over each other #557

avp opened this issue Jun 28, 2014 · 13 comments

Comments

@avp
Copy link

avp commented Jun 28, 2014

I'm having some issues with time-consuming tasks that are watched by gulp.

Suppose task B depends on task A (i.e. task A must run before task B). I watch some files, and I run task B when the files change. then, after task A completes and task B is running, I save the files again - this results in task A starting up again, before task B finishes. Then task B never gets rerun with the second save and I have to go back and resave, and wait for gulp to finish running both task A and B again when it would not have been necessary.

Is there a way for gulp to recognize this overlap in dependencies and either ensure that task B always runs after task A or simply restart both tasks on file change?

@avp avp changed the title gulp.watch gulp.watch Jun 28, 2014
@avp avp changed the title gulp.watch gulp.watch: running the same tasks over each other Jun 28, 2014
@yocontra
Copy link
Member

You can tweak your .watch settings to debounce the events if this happens often https://github.com/shama/gaze#properties

@avp
Copy link
Author

avp commented Jun 28, 2014

The tasks are fairly unpredictable in time, and it's hard to make a debounce very fast - I'm just trying to improve the speed that the task executes many times. If that's not possible, that's fine. The ideal solution would be to stop the tasks and restart task B from scratch.

@pkozlowski-opensource
Copy link
Contributor

@avp funny enough, I'm kind off also trying to make the live-reload fire exactly once for a situation where watch executes other tasks, exactly like in your setup. Today I've started a discussion in the livereload plugin (gulp-community/gulp-livereload#36).

Playing with debounce settings, as suggested by @contra, is a remedy sometimes but it would be great to have a reliable way of detecting that all the tasks enumerated as watch dependencies have executed. @contra would it make sense to emit an event / provide a callback when all the tasks are finished?

@yocontra
Copy link
Member

@robrich Doesn't orchestrator have a concept of "tasks running" to make sure different sets trigger one after another?

@pkozlowski-opensource
Copy link
Contributor

From the quick scanning over the orchestrator code it looks like it will emit the stop event if a given task / sequence of tasks is done: https://github.com/orchestrator/orchestrator/blob/18831d3db0448910d49208d790256dc879b8e9e6/index.js#L284

The case where watch would start a new task / sequence of tasks when previous tasks are still in progress seems to be handled as well.

So, maybe it would make sense to register a listener on the 'stop' event in gulp.watch and propagate is to the "outside world" somehow (event / callback)?

@robrich
Copy link
Contributor

robrich commented Jul 13, 2014

Yes, orchestrator will ensure a given task is running only once. Do you have a gulpfile that demonstrates this symptom?

@pkozlowski-opensource
Copy link
Contributor

@robrich I think that orchestrator does the right thing - this is more a feature request than a bug report. The whole story started with the quest for a better integration with live-reload. Basically given a setup like this:

gulp.watch('src/**/*.js', ['foo', 'bar']);

I would like to know when foo and bar are "done" so I can trigger live-reload. Basically I'm after something like this (or any other notification system):

gulp.watch('src/**/*.js', ['foo', 'bar'], function(err){
  //Here I know that both 'foo' and 'bar' have finished and they have errored or not
});

But then again, this is more like a feature request for gulp, I believe.
The fully story about current troubles with gulp + livereload integration here: gulp-community/gulp-livereload#36

@avp
Copy link
Author

avp commented Jul 14, 2014

I think this may be different from my problem, which can be illustrated as follows:

gulp.watch('*.js', ['a', 'b']);

The gulp output order is something like

start 'a'
stop 'a'
start 'b'
start 'a' // I edit foo.js
stop 'a'
stop 'b'

In the above, b never gets run again for the second run of a.

@yocontra
Copy link
Member

yocontra commented Sep 1, 2014

@phated Thoughts about this for gulp 4?

@phated
Copy link
Member

phated commented Sep 4, 2014

@contra this should come out of the box by using gulp.series as your watch function.

@himynameisdave
Copy link

Article about task-dependency in Gulp:
woot woot task dependencies

@yocontra
Copy link
Member

Cool - I'll close this since it has been fixed in gulp 4. You can use the gulp4 branch from github for now until we publish

@adamreisnz
Copy link

Nevermind, it's a different isuse

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants