Security News
npm Updates Search Experience with New Objective Sorting Options
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
@types/async-lock
Advanced tools
@types/async-lock provides TypeScript type definitions for the async-lock library, which is used to manage asynchronous locks in JavaScript. This package helps ensure that your code is type-safe when using async-lock.
Basic Locking
This feature allows you to create a lock on a specific key, ensuring that the critical section of code is executed exclusively.
const AsyncLock = require('async-lock');
const lock = new AsyncLock();
lock.acquire('key', function(done) {
// Critical section
console.log('Locked section');
done();
}, function(err, ret) {
// Lock released
console.log('Lock released');
});
Timeouts
This feature allows you to set a timeout for the lock. If the lock is not acquired within the specified time, an error is returned.
const AsyncLock = require('async-lock');
const lock = new AsyncLock();
lock.acquire('key', function(done) {
// Critical section
setTimeout(() => {
console.log('Locked section with timeout');
done();
}, 2000);
}, { timeout: 1000 }, function(err, ret) {
if (err) {
console.log('Lock timeout');
} else {
console.log('Lock released');
}
});
Multiple Keys
This feature allows you to acquire locks on multiple keys simultaneously, ensuring that the critical section is executed only when all specified keys are locked.
const AsyncLock = require('async-lock');
const lock = new AsyncLock();
lock.acquire(['key1', 'key2'], function(done) {
// Critical section
console.log('Locked section with multiple keys');
done();
}, function(err, ret) {
// Lock released
console.log('Lock released');
});
async-mutex provides a similar functionality to async-lock by offering mutexes and read-write locks for asynchronous code. It is simpler and more focused on mutexes compared to async-lock.
semaphore-async-await provides semaphore and mutex implementations for async/await in JavaScript. It offers more advanced synchronization primitives compared to async-lock.
await-lock is a lightweight implementation of a lock for async/await. It is simpler and more lightweight compared to async-lock, focusing solely on providing a basic lock mechanism.
npm install --save @types/async-lock
This package contains type definitions for async-lock (https://github.com/rain1017/async-lock).
Files were exported from https://www.github.com/DefinitelyTyped/DefinitelyTyped/tree/types-2.0/async-lock
Additional Details
These definitions were written by Elisée MAURER https://github.com/elisee/.
FAQs
TypeScript definitions for async-lock
We found that @types/async-lock demonstrated a not healthy version release cadence and project activity because the last version was released 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
npm has a revamped search experience with new, more transparent sorting options—Relevance, Downloads, Dependents, and Publish Date.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.