
Security News
Feross on TBPN: How North Korea Hijacked Axios
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.
synchronized-ts
Advanced tools
This library provides a mutex that works with async functions. It guarantees that a certain async code section is never executed concurrently. ⚙️⚡
Furthermore, it provides an @synchronized decorator for usage in typescript.
yarn add synchronized-ts
# or
npm i synchronized-ts
Synchronized decorator:
class Runner {
private taskId: number
constructor(taskId: number) { this.taskId = taskId }
// Synchronized works on methods.
@synchronized
public async run() {
console.log(`Begin ${this.taskId}`)
// Do some async work.
console.log(`End ${this.taskId}`)
}
}
Locking based on context:
const synchronizePayment = new MutexLibrary<number>()
app.post('/payment/:userId?', async (ctx: any) => {
const userId = ctx.params.userId
ctx.response.body = await synchronizePayment.by(userId).sync(async () => {
// Do dangerous things that can never race for a user.
return 0
})
})
Global locking:
const synchronizePayment = new Mutex<number>()
app.post('/signup/', async (ctx: any) => {
ctx.response.body = await synchronizePayment.sync(async () => {
// Do dangerous things that can never race at all.
return 0
})
})
For more detailed examples, please look into the examples and test folders.
Generally speaking, you should always aim for lock-free concurrency mechanisms when building web applications. However, there might be corner cases: I ran into a case with 3rd party APIs, where executing concurrent calls to certain API in the same user context broke things, hence I wrote this library.
FAQs
Mutex and @synchronized TS decorator
The npm package synchronized-ts receives a total of 244 weekly downloads. As such, synchronized-ts popularity was classified as not popular.
We found that synchronized-ts 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
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.

Security News
OpenSSF has issued a high-severity advisory warning open source developers of an active Slack-based campaign using impersonation to deliver malware.

Research
/Security News
Malicious packages published to npm, PyPI, Go Modules, crates.io, and Packagist impersonate developer tooling to fetch staged malware, steal credentials and wallets, and enable remote access.