
Research
/Security News
Shai Hulud Strikes Again (v2)
Another wave of Shai-Hulud campaign has hit npm with more than 500 packages and 700+ versions affected.
@hitorisensei/mutex-decorator
Advanced tools
This library provides two TypeScript decorators, Mutex and ReentrantMutex, for locking methods to ensure mutual exclusion in asynchronous contexts.
Under the hood, the library uses composable-locks to provide the Mutex locking mechanism.
In contrast to composable-locks, the ReentrantMutex decorator doesn't depend on domain symbols use and instead uses AsyncLocalStorage to keep the recursive lock state.
NOTE: This library is intended to be used by TypeScript projects.
Projects must have the experimentalDecorators option enabled in the tsconfig.json file.
{
"compilerOptions": {
"experimentalDecorators": true,
}
}
Install the library using npm:
npm install composable-locks
The Mutex decorator ensures that the decorated method is locked with a mutex, allowing only one execution at a time. It queues concurrent calls and executes them sequentially.
import { Mutex } from './mutex';
class ExampleClass {
@Mutex
async criticalSection() {
// Your code here
}
}
const instance = new ExampleClass();
instance.criticalSection();
The ReentrantMutex decorator allows reentrant locking in the same asynchronous context. It uses AsyncLocalStorage to check if the lock is already acquired in the current async context.
Because the use of AsyncLocalStorage is used, a minimal performance and/or memory overhead is expected. Thus, it is recommended to use ReentrantMutex only when recursive calls are expected.
import { ReentrantMutex } from './reentrantMutex';
class ExampleClass {
@ReentrantMutex
async criticalSection() {
// Your code here
}
}
const instance = new ExampleClass();
instance.criticalSection();
The library includes tests for both decorators using Jest. To run the tests, use the following command:
npm test
This project is licensed under the MIT License.
FAQs
Mutex and Re-entrant Mutex Decorators for TypeScript
We found that @hitorisensei/mutex-decorator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Another wave of Shai-Hulud campaign has hit npm with more than 500 packages and 700+ versions affected.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.