diff --git a/CHANGELOG.md b/CHANGELOG.md index f81a397..ae2f3a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/). --- +## [2.0.0] - 2025-11-17 + +### Changed +- `lock(name).request()` now returns `Promise` instead of `Promise`. +- When a lock cannot be acquired (e.g., `ifAvailable: true`), `null` is returned instead of a dummy object. +- Ensures compatibility with `await using` and AsyncDisposable patterns. + +--- + ## [1.0.1] - 2025-11-14 ### Fixed @@ -28,5 +37,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/). --- +[2.0.0]: https://github.com/juner/disposable-lock/releases/tag/v2.0.0 [1.0.1]: https://github.com/juner/disposable-lock/releases/tag/v1.0.1 [1.0.0]: https://github.com/juner/disposable-lock/releases/tag/v1.0.0 diff --git a/README.md b/README.md index dab375e..1193eed 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ async function main() { // Request a lock const acquired = await request({ mode: "exclusive" }); - if (acquired.name) { + if (acquired) { console.log(`✅ Lock acquired: ${acquired.name}`); // Do something critical @@ -62,7 +62,12 @@ async function autoRelease() { // Automatically releases the lock when the block ends await using acquired = await cacheLock.request(); - console.log("Inside critical section..."); + if (acquired) { + // Do something critical + await doSomething(); + } else { + console.warn("⚠️ Lock was not available"); + } } ``` @@ -76,7 +81,7 @@ Returns an object with: | Method | Description | - | - -| `request(options?: LockOptions)` | Request a lock. Returns a `ReleasableLock` or a `NotHaveLock`. +| `request(options?: LockOptions)` | Request a lock. Returns a `ReleasableLock` or a null. | `query()` | Query the current state (held and pending locks) for this name. Throws if `navigator.locks` is unavailable and no custom `LockManager` is provided. @@ -94,16 +99,6 @@ Represents a successfully acquired lock. | `release()` | `() => Promise` | Releases the lock | `[Symbol.asyncDispose]()` | `() => Promise` | Enables await using syntax -### `NotHaveLock` - -Returned when the lock cannot be obtained (for example, when using `{ ifAvailable: true }`). - -| Property / Method | Type | Description -| `name` | `undefined` | — -| `mode` | `undefined` | — -| `release()` | `() => Promise` | No-op release -| `[Symbol.asyncDispose]()` | `() => Promise` | No-op - ## Querying lock state ```ts diff --git a/package-lock.json b/package-lock.json index f624e54..a3b8bea 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "disposable-lock", - "version": "1.0.1", + "version": "2.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "disposable-lock", - "version": "1.0.1", + "version": "2.0.0", "license": "MIT", "devDependencies": { "@eslint/js": "^9.39.1", diff --git a/package.json b/package.json index 97475d3..f982cdb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "disposable-lock", - "version": "1.0.1", + "version": "2.0.0", "description": "A disposable lock controller that wraps navigator.locks", "type": "module", "main": "./index.js",