Still receiving lines after calling unwatch
See original GitHub issueI’m using chokidar to watch for add
and unlink
events for certain file paths and initializing a new Tail instance when a file is added and unwatching it when the file is unlinked.
However, despite unwatching the Tail in the unlink
handler, the Tail line callback is still being invoked once the file is re-added to the file system. I end up having multiple instances of Tail still watching the file.
const watcher = chokidar.watch(watchDirectoryPath, {
persistent: true,
depth: 0
});
let tail = undefined;
// Start watching files
watcher.on("add", (filePath: string) => {
if (tail != null) {
tail.unwatch();
}
const newTail = new Tail(filePath);
newTail.on("line", (line: string) => {
if (line.length <= 0) {
return;
}
if (tail !== newTail) {
console.error("inactive tail is still producing lines!");
}
console.log(line);
});
newTail.on("error", () => {
// Suppress error
});
tail = newTail;
});
// Stop watching files
watcher.on("unlink", (filePath: string) => {
if (tail != null) {
tail.unwatch();
}
});
Note: This is a very simple version of the code that I’m actually running. If a file is added, written to, removed, then re-added and written to again, the second time the lines will be duplicated along with error messages saying “inactive tail is still producing lines!” from my explicit check in the line callback.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
ruby on rails - Redis gem watch and unwatch confusion
So there is indeed a reason to use UNWATCH. If the multi block is not called then EXEC is not called either. Then...
Read more >Everything You Need to Know About Receiving Lines - Brides
Receiving lines are an incredibly useful way to make sure you have a chance to greet all of your wedding guests, especially at...
Read more >In certain circumstances, the Stop Watching functionality ... - Jira
In certain circumstances, the Stop Watching functionality does not work correctly when unwatching issues reported by you while Autowatch is enabled.
Read more >Ability to disable/not trigger watch handler on data? #1829
$watch return a handler to unwatch function, which I can call it when I want to stop watch, after that I watch the...
Read more >Etiquette Q&A: "Do We Need to Have a Receiving Line?"
Consider having a smaller receiving line after the ceremony: The traditional line, which includes parents and attendants, can be shortened to just the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
fix available in v2.0.4.
I actually don’t know why a rename event was triggering because I’m not renaming files, only adding and removing them continuously. Although I’ve read that the built-in
fs.watch
andfs.watchFile
have issues with producing incorrect events. That’s the whole reason why chokidar exists: https://github.com/paulmillr/chokidar/blob/master/README.md#why