Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@hitorisensei/mutex-decorator
Advanced tools
Mutex and Re-entrant Mutex Decorators for TypeScript
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
The npm package @hitorisensei/mutex-decorator receives a total of 1 weekly downloads. As such, @hitorisensei/mutex-decorator popularity was classified as not popular.
We found that @hitorisensei/mutex-decorator demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.