grunt-contrib-watch icon indicating copy to clipboard operation
grunt-contrib-watch copied to clipboard

Emit an event when gaze has finished setting up

Open dtyler opened this issue 10 years ago • 5 comments

Once all of the setup tasks required to react to changes on the file system are complete, emit an event.

Use case: When watching a large number of files it can take some time to glob for all of the requested files and make the inotify request. By watching for this event, a message can be written to the console after setup is complete and future changes will be detected.

dtyler avatar May 14 '14 18:05 dtyler

:+1:

edasque avatar May 14 '14 19:05 edasque

I think this will require more thought. Events don't work well with Grunt. You can't do much with an event besides logging so I think just logging a Waiting... message once gaze is actually ready would be a better idea.

Also this implementation would fire the event for each target that is ready. I think it would be better to just log once when all watched targets are ready.

shama avatar May 20 '14 04:05 shama

I've corrected the improper placement of my event generation just in case, but I'd also be fine with moving the existing Waiting... message if we decide that's the better behavior. I assumed that the existing message was where it was for a reason and thought an event-based solution would allow those who wanted the supplemental messaging could opt into it, while leaving the existing behavior unchanged for everyone else.

dtyler avatar May 20 '14 13:05 dtyler

@shama Any thoughts on my response? I'd like to know for sure so that I can update my pull request.

dtyler avatar Jun 02 '14 17:06 dtyler

The location you moved the event still won't emit once all watchers are actually ready. You would need to track how many watchers we will be opening, then once all have stated they're ready, emit the event.

Something like:

var targetsCount = targets.length;
function watcherIsReady() {
  targetsCount--;
  // Only call when all watchers indicated they're ready
  if (targetsCount < 1) self.emit('watch.ready');
}
watchers.push(new Gaze(patterns, target.options, function(err) {
  // Call each time a watcher is ready
  watcherIsReady();
}));

But I still don't know if the event is a good route. People will abuse the event and open up issues about why scenario X doesn't work (it already happens way too much with the watch event). But I do see the value in it, such as I would like to emit a beep noise when the watch is ready but lots of people dislike beeps and will complain if I add it to the default Wating... message.

I just need to ask around more for more opinions on it. Thanks for being patient with me.

shama avatar Jun 02 '14 17:06 shama