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

Emit an event when gaze has finished setting up #332

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dtyler
Copy link

@dtyler dtyler commented May 14, 2014

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.

@edasque
Copy link

edasque commented May 14, 2014

👍

@shama
Copy link
Member

shama commented May 20, 2014

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.

@dtyler
Copy link
Author

dtyler commented May 20, 2014

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
Copy link
Author

dtyler commented Jun 2, 2014

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

@shama
Copy link
Member

shama commented Jun 2, 2014

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.

Base automatically changed from master to main March 22, 2021 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants