You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,7 @@ This package extends [zero-overhead-promise-lock](https://www.npmjs.com/package/
24
24
-__Key-wise Mutual Exclusiveness :lock:__: Ensures the mutually exclusive execution of tasks **associated with the same key**, either to prevent potential race conditions caused by tasks spanning across multiple event-loop iterations, or to optimize performance.
25
25
-__Graceful Teardown :hourglass_flowing_sand:__: Await the completion of all currently pending and executing tasks using the `waitForAllExistingTasksToComplete` method. Example use cases include application shutdowns (e.g., `onModuleDestroy` in Nest.js applications) or maintaining a clear state between unit-tests. A particularly interesting use case is in **batch processing handlers**, where it allows you to signal the completion of all event handlers associated with a batch.
26
26
-__"Check-and-Abort" Friendly :see_no_evil:__: The `isActiveKey` getter allows skipping or aborting operations if a lock is already held.
27
+
-__Smart Reuse :recycle:__: In scenarios where launching a duplicate task would be wasteful (e.g., refreshing a shared resource or cache), consumers can **await the ongoing execution instead of scheduling a new one**. This is enabled via the `getCurrentExecution` method, which exposes the currently executing task's promise for a specific key, if one is active.
27
28
-__Active Key Metrics :bar_chart:__: The `activeKeys` getter provides real-time insight into currently active keys - i.e., keys associated with ongoing tasks.
28
29
-__Even-Driven Eviction of Stale Keys__: Automatically removes internal locks for keys with no pending or ongoing tasks, ensuring the lock never retains stale keys.
29
30
-__Comprehensive documentation :books:__: Fully documented to provide rich IDE tooltips and enhance the development experience.
@@ -39,6 +40,7 @@ The `ZeroOverheadKeyedLock` class provides the following methods:
39
40
*__executeExclusive__: Executes the given task in a controlled manner, once the lock is available. It resolves or rejects when the task finishes execution, returning the task's value or propagating any error it may throw.
40
41
*__waitForAllExistingTasksToComplete__: Waits for the completion of all tasks that are *currently* pending or executing. This method is particularly useful in scenarios where it is essential to ensure that all tasks - whether already executing or queued - are fully processed before proceeding. Examples include **application shutdowns** (e.g., `onModuleDestroy` in Nest.js applications) or maintaining a clear state between unit tests.
41
42
*__isActiveKey__: Indicates whether the provided key is currently associated with an ongoing task (i.e., the task is not yet completed). This property is particularly useful in "check and abort" scenarios, where an operation should be skipped or aborted if the key is currently held by another task.
43
+
*__getCurrentExecution__: Exposes the currently executing task's promise for a specific key, if one is active. This is useful in scenarios where launching a duplicate task would be wasteful - consumers can simply **await the ongoing execution instead**. This feature enhances the lock’s versatility and supports advanced usage patterns.
42
44
43
45
If needed, refer to the code documentation for a more comprehensive description of each method.
0 commit comments