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.
Used for debugging to keep track of the watchers.
This deferred only rejects with
WatcherDisposal and never resolves.
When the ref count hits zero, we schedule this watch handle to be disposed.
When this field is set, it means the nsfw instance was successfully started.
Ensures that events are processed in the order they are emitted, despite being processed async.
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.
Resolves once this handle disposed itself and its resources. Never throws.
Promise that resolves when the watcher is fully started, or got disposed.
Will reject if an error occurred while starting.
Internal disposal mechanism.
All clients with at least one active reference.
Add the references for each client together.
Returns true if at least one client listens to this handle.
When references hit zero, we'll schedule disposal for a bit later.
This allows new references to reuse this watcher instead of creating a new one.
e.g. A frontend disconnects for a few milliseconds before reconnecting again.
If we get new references after hitting zero, let's unschedule our disposal and keep watching.
When starting a watcher, we'll first check and wait for the path to exists before running an NSFW watcher.
Given a started nsfw instance, gracefully shut it down.