Repository navigation
feat: stop watching for updates with an AbortSignal - #1002
Merged
Merged
Conversation
open() with watchForUpdates registers an fs.watchFile listener that nothing can remove. A persistent watcher then keeps the process alive at shutdown, and opening the database again adds another listener that keeps reloading the old reader. Add a `signal` option. Aborting it removes the listener and ignores a change that was already being handled; the reader keeps serving the database it has loaded. An already-aborted signal does not start a watcher.
Owner
|
Thanks for the addition! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #1000.
Problem
open()withwatchForUpdates: trueregisters anfs.watchFilelistener, and nothing can remove it:process.exit()orwatchForUpdatesNonPersistent;Change
A new
signaloption, the standardAbortSignalpattern:fs.unwatchFilewith the same listener.The option is additive, so existing calls behave as before. The README documents it.
Tests
unwatchFile(path, listener)and that a queued change is then ignored. The other checks that an already-aborted signal starts no watcher. Both fail onmaster.npm test: 59 passed.tscand prettier are clean.open()followed byabort()lets the process exit right away. Without the signal, it keeps running.