Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@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://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/async-lock.
// Type definitions for async-lock 1.1
// Project: https://github.com/rain1017/async-lock, https://github.com/rogierschouten/async-lock
// Definitions by: Alejandro <https://github.com/afharo>
// Anatoly <https://github.com/rhymmor>
// Humulus <https://github.com/humulus>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.1
type AsyncLockDoneCallback<T> = (err?: Error, ret?: T) => void;
interface AsyncLockOptions {
timeout?: number | undefined;
maxPending?: number | undefined;
maxOccupationTime?: number | undefined;
domainReentrant?: boolean | undefined;
Promise?: any;
skipQueue?: boolean | undefined;
}
declare class AsyncLock {
constructor(options?: AsyncLockOptions);
acquire<T>(key: string | string[],
fn: (() => T | PromiseLike<T>) | ((done: AsyncLockDoneCallback<T>) => any),
opts?: AsyncLockOptions): Promise<T>;
acquire<T>(key: string | string[],
fn: (done: AsyncLockDoneCallback<T>) => any,
cb: AsyncLockDoneCallback<T>,
opts?: AsyncLockOptions): void;
isBusy(key?: string): boolean;
}
declare namespace AsyncLock { }
export = AsyncLock;
These definitions were written by Alejandro, Anatoly, and Humulus.
FAQs
TypeScript definitions for async-lock
The npm package @types/async-lock receives a total of 370,792 weekly downloads. As such, @types/async-lock popularity was classified as popular.
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
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.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.