From 2f2a85852feb4dd20c74ba6e36529e712807f543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Fri, 26 Nov 2021 17:17:39 +0100 Subject: [PATCH] Update README.md (#364) --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 025c9a1..4d70b4a 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,20 @@ npm install fsevents ```js const fsevents = require('fsevents'); + +// To start observation const stop = fsevents.watch(__dirname, (path, flags, id) => { const info = fsevents.getInfo(path, flags, id); -}); // To start observation -stop(); // To end observation +}); + +// To end observation +stop(); ``` +> **Important note:** The API behaviour is slightly different from typical JS APIs. The `stop` function **must** be +> retrieved and stored somewhere, even if you don't plan to stop the watcher. If you forget it, the garbage collector +> will eventually kick in, the watcher will be unregistered, and your callbacks won't be called anymore. + The callback passed as the second parameter to `.watch` get's called whenever the operating system detects a a change in the file system. It takes three arguments: