-
Notifications
You must be signed in to change notification settings - Fork 167
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
Immediately exits when watching an empty directory #40
Comments
I can't get this to work either. I have almost identical code |
Same problem here. |
I think we should handle this in the implementation of gaze rather than internally. As we would need to detect if no files were matched and then purposely keep the process alive. Which could be annoying and hacky for those who don't want the behavior. Especially since it's easy to keep a process alive with FWIW, I'm planning on forcefully keeping grunt-contrib-watch alive to wait for added files even when the files dont yet exist. I encourage others using this lib to do the same approach if needed. Thanks! |
API-wise this is counter-intuitive: The workflow looks to be like: Start Gaze -> Wait for files to come/change (.close() gaze manually if isn't needed anymore). Now the workflow is like: Start Gaze -> Wait for files to come/change + Watch out for possible end event that could occur for without telling gaze to stop. In other words: I was hoping that gaze would just run forever with any given input pattern - a wonderful thing - but instead I am confronted with: may break or end under certain circumstances making it more of a hazzle to work with. |
It's really not that dire, imo: var interval = setInterval(function() {}, 200); // keep the process alive
require('gaze')('**/*.js', function() {
this.on('all', function(event, filepath) {
console.log(filepath + ' has ' + event);
});
this.on('end', function() {
clearInterval(interval); // stop the process
});
}); or more simply, We could handle this within gaze as you suggested but doing so means we're limiting the user's control over the process. What if a user wants their process to exit if no files match (as the current library does)? It seems equally as cumbersome for that user to check if no files have been matched then purposely exit the process. I'm definitely open to discussing this if you feel strongly about it though. |
My point was supposed to be that - in terms of API design - the current version feels harder to read and less intuitive than it could be. But I agree to your point: it is actually a useful information if there is no match to any pattern. However: that information is also useful after you started (to) gaze. How about this API: var Gaze = require("gaze").Gaze;
var geezer = new Gaze("**/*.js");
geezer.on("no-match", function() {
geezer.close();
});
geezer.on("all", function() {
// ...
}); Now the process would elegantly close whenever there is no match happening, no matter if it happens on the startup or after someone deleted some files. |
Not a bad idea especially since I'll need that for this issue: gruntjs/grunt-contrib-watch#183 Let me give this some more thought. Reopening. |
Added a |
Due this issues: * shama/gaze#98 * shama/gaze#40 Closes #25
I'm having trouble setting up a watcher for a certain file type in a directory that starts out empty.
Am I just misunderstanding how this works, or has something gone wrong?
The text was updated successfully, but these errors were encountered: