• Public
  • Public/Protected
  • All

Because URIs can be watched by different clients, we'll track how many are listening for a given URI.

This component wraps the whole start/stop process given some reference count.

Once there are no more references the handle will wait for some time before destroying its resources.


  • NsfwWatcher




debugId: number = ...

Used for debugging to keep track of the watchers.

deferredDisposalDeferred: Deferred<never> = ...

This deferred only rejects with WatcherDisposal and never resolves.

deferredDisposalTimeout: number = 10_000
deferredDisposalTimer: undefined | Timer

When the ref count hits zero, we schedule this watch handle to be disposed.

disposed: boolean = false
fileSystemWatcherClient: FileSystemWatcherServiceClient
fsPath: string
nsfw: undefined | NSFW

When this field is set, it means the nsfw instance was successfully started.

nsfwEventProcessingQueue: Promise<void> = ...

Ensures that events are processed in the order they are emitted, despite being processed async.

nsfwFileSystemWatchServerOptions: NsfwFileSystemWatcherServerOptions
refsPerClient: Map<number, { value: number }> = ...

We count each reference made to this watcher, per client.

We do this to know where to send events via the network.

An entry should be removed when its value hits zero.

watcherOptions: NsfwWatcherOptions
whenDisposed: Promise<void> = ...

Resolves once this handle disposed itself and its resources. Never throws.

whenStarted: Promise<boolean>

Promise that resolves when the watcher is fully started, or got disposed.

Will reject if an error occurred while starting.


true if successfully started, false if disposed early.

debugIdSequence: number = 0


  • _dispose(): Promise<void>
  • addRef(clientId: number): void
  • assertNotDisposed(): void
  • createNsfw(): Promise<NSFW>
  • debug(prefix: string, ...params: any[]): void
  • fireError(): void
  • getClientIds(): number[]
  • getTotalReferences(): number
  • handleNsfwEvents(events: FileChangeEvent[]): void
  • info(prefix: string, ...params: any[]): void
  • isIgnored(filePath: string): boolean
  • isInUse(): boolean
  • onRefsReachZero(): void
  • onRefsRevive(): void
  • removeRef(clientId: number): void
  • resolveEventPath(directory: string, file: string): Promise<string>
  • start(): Promise<void>
  • stopNsfw(watcher: NSFW): Promise<void>