
Security News
US Government Forces Anthropic to Pull Claude Fable Days After Launch
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.
@hazeljs/distributed-lock
Advanced tools
Distributed locking and synchronization primitives for HazelJS - Mutex, Semaphores, Read/Write locks
Distributed Locking for HazelJS. Mutual exclusion across all your nodes, simplified.
Ensure that your critical code paths are only executed by one instance at a time. HazelJS Distributed Lock provides a unified interface for multiple backends (Redis, In-Memory) and a powerful decorator-based API with dynamic key resolution.
@DistributedLock() for declarative, method-level locking across your distributed system.{id}, {user.token}) that automatically resolve from method arguments.npm install @hazeljs/distributed-lock
For production environments using Redis, you'll need the following:
npm install redis
The easiest way to use distributed locking is through the @DistributedLock decorator.
Lock a method for a specific user based on an argument.
import { DistributedLock } from '@hazeljs/distributed-lock';
class UserProfileService {
@DistributedLock({
key: 'update-profile-{userId}',
ttl: 10000,
wait: true,
})
async updateProfile(userId: string, data: any) {
// This code is now thread-safe across all distributed nodes
// for this specific userId.
return await this.saveProfile(userId, data);
}
}
You can also acquire and release locks manually using the LockManager.
import { LockManager } from '@hazeljs/distributed-lock';
const lockManager = LockManager.getInstance();
async function myTask() {
const lock = await lockManager.acquire({
key: 'manual-task-lock',
ttl: 5000,
});
if (!lock) return; // Could not acquire lock
try {
// Perform critical task...
} finally {
// Always release in finally block
await lock.release();
}
}
Choose the backend that fits your deployment strategy.
Great for development or single-node deployments.
import { LockManager } from '@hazeljs/distributed-lock';
const lockManager = LockManager.getInstance();
lockManager.setDefaultBackend('memory');
Recommended for multi-node production systems.
import { LockManager } from '@hazeljs/distributed-lock';
const lockManager = LockManager.getInstance();
lockManager.setupRedis(
{
url: 'redis://localhost:6379',
},
'redis-prod'
);
lockManager.setDefaultBackend('redis-prod');
| In-Memory | Redis | Custom | |
|---|---|---|---|
| Distributed | ❌ (Single node) | ✅ (All nodes) | ✅ (Interface-based) |
| Setup | None | Required | Custom impl |
| Best For | Development / Testing | Production / High Load | Specialized systems |
| Performance | Nano-seconds | Milli-seconds | Backend-dependent |
| Option | Type | Description |
|---|---|---|
key | string | The unique lock identifier. Supports {param} placeholders from method args. |
ttl | number | Time-To-Live in milliseconds. Default: 5000. |
wait | boolean | If true, will wait for the lock if held. Default: false. |
retryCount | number | Number of retries if wait is true. Default: 3. |
retryDelay | number | Time between retries in milliseconds. Default: 100. |
backend | string | Override the default backend (e.g., 'memory', 'redis'). |
LockManager (Singleton)class LockManager {
static getInstance(): LockManager;
registerBackend(name: string, backend: ILockBackend): void;
setDefaultBackend(name: string): void;
acquire(options: LockOptions): Promise<ILock | null>;
setupRedis(redisOptions: any, name?: string): void;
}
InterfacesILock — An acquired lock. Contains release(): Promise<void>.ILockBackend — The interface for implementing custom lock providers.Apache-2.0
Contributions are welcome! See CONTRIBUTING.md for details.
FAQs
Distributed locking and synchronization primitives for HazelJS - Mutex, Semaphores, Read/Write locks
The npm package @hazeljs/distributed-lock receives a total of 21 weekly downloads. As such, @hazeljs/distributed-lock popularity was classified as not popular.
We found that @hazeljs/distributed-lock demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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.

Security News
Anthropic says the directive cited national security concerns over a narrow jailbreak, but offered no specific technical details.

Security News
A network of 152 Chrome live wallpaper extensions hid ad tracking and made extension-driven traffic look like Google search clicks.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.