Skip to content

Commit

Permalink
protofile: use watchFile instead of watch
Browse files Browse the repository at this point in the history
Using fs.watchFile seems to work on more cases than simply using watch.

Partially fixes issue discussed in #5
  • Loading branch information
w4tsn committed Jul 10, 2020
1 parent fff792f commit 57d0021
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/nodes/protofile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ module.exports = function (RED) {
if (protoFileNode.prototypes === undefined) return;

try {
protoFileNode.protoFileWatcher = fs.watch(config.protopath, (eventType) => {
protoFileNode.protoFileWatcher = fs.watchFile(config.protopath, (eventType) => {
if (eventType === 'change') {
load();
protoFileNode.warn('Protobuf file changed on disk. Reloaded.');
}
});
protoFileNode.on('close', () => {
protoFileNode.protoFileWatcher.close();
});
protoFileNode.on('close', () => fs.unwatchFile(config.protopath));
}
catch (error) {
protoFileNode.error('Error when trying to watch the file on disk: ' + error);
Expand Down

0 comments on commit 57d0021

Please sign in to comment.