I'm watching multiple network folders using fs.watch()
, each on a different IP. The problem is that sometimes these network drives go offline, and I need to retry watching them until they go online.
The code I wrote looks like this:
watchFolder() {
var self = this
let path = `\\\\${this.pathIP}\\folder1`
try {
fs.watch(path, (eventType, filename) => {
...
}
}
catch (err) {
//drive is offline
setTimeout ( () => {
this.watchFolder()
}, 1000);
}
}
I tried calling the same function from the catch
every second, so that if it goes online it would continue normally, but apparently this takes too much memory because of the recursion. What can be an alternative way to do what I am trying to achieve?