Skip to content

Commit

Permalink
Always return a promise from the stopper function (#296)
Browse files Browse the repository at this point in the history
* feat: always return a promise from the stopper function

* Use undefined instead of null.

* Update README.md
  • Loading branch information
SimenB authored and paulmillr committed Nov 9, 2019
1 parent 5ca31f3 commit 6722e56
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -30,13 +30,13 @@ stop(); // To end observation
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:

###### `fsevents.watch(dirname: string, (path: string, flags: number, id: string) => void): Function`
###### `fsevents.watch(dirname: string, (path: string, flags: number, id: string) => void): () => Promise<undefined>`

* `path: string` - the item in the filesystem that have been changed
* `flags: number` - a numeric value describing what the change was
* `id: string` - an unique-id identifying this specific event
Returns closer callback.

Returns closer callback which when called returns a Promise resolving when the watcher process has been shut down.

###### `fsevents.getInfo(path: string, flags: number, id: string): FsEventInfo`

Expand Down
6 changes: 4 additions & 2 deletions fsevents.js
Expand Up @@ -24,8 +24,10 @@ function watch(path, handler) {
let instance = Native.start(path, handler);
if (!instance) throw new Error(`could not watch: ${path}`);
return () => {
const result = instance ? Promise.resolve(instance).then(Native.stop) : null;
instance = null;
const result = instance
? Promise.resolve(instance).then(Native.stop).then(() => undefined)
: Promise.resolve(undefined);
instance = undefined;
return result;
};
}
Expand Down

0 comments on commit 6722e56

Please sign in to comment.