From bbbae55f817b5f89884bbef4ab6a5742c9623233 Mon Sep 17 00:00:00 2001 From: Philipp Dunkel Date: Thu, 4 Feb 2021 21:28:37 +0000 Subject: [PATCH 1/2] Retain ref to stop You have to retain a reference to the stop function or the watching will be automatically stopped. --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 4fe1d29..a3cb928 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,12 @@ const fsevents = require('fsevents'); -fsevents.watch(`${__dirname}/watched`, (path, flags, id) => { +const stop = fsevents.watch(`${__dirname}/watched`, (path, flags, id) => { const info = fsevents.getInfo(path, flags, id); console.log(info) }); setInterval(() => { console.log("tick") -}, 60000); \ No newline at end of file +}, 60000); +setTimeout(() => { + stop(); + console.log('stoped watching'); +}, 3600000); From ceff02ec1b37b5b46a392625f35d6a0855a705b1 Mon Sep 17 00:00:00 2001 From: Sun Knudsen Date: Thu, 4 Feb 2021 21:39:02 +0000 Subject: [PATCH 2/2] Fixed typo --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index a3cb928..00c3cf0 100644 --- a/index.js +++ b/index.js @@ -8,5 +8,5 @@ setInterval(() => { }, 60000); setTimeout(() => { stop(); - console.log('stoped watching'); + console.log('stopped watching'); }, 3600000);