Skip to content

Add isLocked() to Storage and EventStore#312

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/add-method-check-storage-lock
Draft

Add isLocked() to Storage and EventStore#312
Copilot wants to merge 2 commits into
mainfrom
copilot/add-method-check-storage-lock

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 10, 2026

There was no public API for clients to check whether a storage is currently locked by a writer — particularly useful for read-only consumers who want to know if a writer is active without attempting to acquire the lock themselves.

Changes

  • ReadableStorage: moves lockFile path computation into the base class constructor (was only in WritableStorage); adds isLocked() returning fs.existsSync(this.lockFile).
  • WritableStorage: removes now-redundant this.lockFile assignment (inherited); lock() now uses isLocked() as the primary pre-check before mkdirSync, with the EEXIST catch retained for the race-condition edge case.
  • EventStore: adds isLocked() delegating to this.storage.isLocked().

Usage

const writer = new EventStore({ storageDirectory });
const reader = new EventStore({ storageDirectory, readOnly: true });

reader.isLocked(); // true — writer is holding the lock
writer.close();
reader.isLocked(); // false

Likewise available directly on Storage and ReadOnlyStorage:

const reader = new Storage.ReadOnly({ dataDirectory });
reader.open();
reader.isLocked(); // true if a WritableStorage has the lock, false otherwise

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants