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.
await-mutex
Advanced tools
Promised based Mutex for cases where you need to synchronize sequentially the access to a single resource from multiple locations.
A typical use case for a mutex is when multiple asynchronous processes are fired and all of them have to execute another, but the same, asynchronous process as they arrive, one at a time, waiting for previous call (if any) to finish before calling it again.
Let you create an object to perform file appends one at a time.
import * as fs from "fs";
import Mutex from "await-mutex";
export default class FileAppender {
constructor(filename) {
this._filename = filename;
this._mutex = new Mutex();
}
async append(data, options = undefined) {
let unlock = await this._mutex.lock();
fs.appendFile(this._filename, data, options, error => {
unlock();
if (error) {
throw error;
}
});
}
}
import Mutex from "await-mutex";
Creates an instance of Mutex (can not be called without new).
let mutex = new Mutex();
Returns if the mutex instance is (true) or not locked (false).
let unlock = await mutex.lock();
console.log(mutex.isLocked()); // prints true
async function someFunc(mutex) {
let unlock = await mutex.lock(); // wait until mutex is unlocked
setTimeout(unlock, 3000);
console.log(someFunc.name);
}
async function someOtherFunc(mutex) {
let unlock = await mutex.lock(); // wait until mutex is unlocked
console.log(someOtherFunc.name);
}
let mutex = new Mutex();
someFunc(mutex); // prints SomeFunc inmediately
someOtherFunc(mutex); // waits 3 secs for mutex to be unlocked and then prints SomeOtherFunc
With npm do:
npm install --save await-mutex
Take a look to the Contributing Guide
FAQs
Promised based Mutex
We found that await-mutex 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.
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.