diff --git a/src/index.ts b/src/index.ts index 5afd1ea6..921e0195 100644 --- a/src/index.ts +++ b/src/index.ts @@ -448,6 +448,7 @@ export class FSWatcher extends EventEmitter { add(paths_: Path | Path[], _origAdd?: string, _internal?: boolean): FSWatcher { const { cwd } = this.options; this.closed = false; + this._closePromise = undefined; let paths = unifyPaths(paths_); if (cwd) { paths = paths.map((path) => { @@ -524,13 +525,15 @@ export class FSWatcher extends EventEmitter { /** * Close watchers and remove all listeners from watched paths. */ - close(): Promise | undefined { - if (this.closed) return this._closePromise; + close(): Promise { + if (this._closePromise) { + return this._closePromise; + } this.closed = true; // Memory management. this.removeAllListeners(); - const closers: any[] = []; + const closers: Array> = []; this._closers.forEach((closerList) => closerList.forEach((closer) => { const promise = closer();