Usage
npm install --save locked-sync
Synchronize and serialize a piece of code.
Why do you need this in javascript or Node.js. Consider the following code
redis;
If two users run concurrency, the execution order may like this
user1: var val = redis.get('key'); => 1user2: var val = redis.get('key'); => 1user1: redis.set('key', val + 1) => 2user2: redis.set('key', val + 1) => 2
So, you can use locked-sync to avoid it.
const lockedSync = ;const sync = ; { ;} ; ; ; ; // almost same time to get and set
const lockedSync = ;const sync = ; { const end = await ; try const val = await redis; await redis; finally ; // Always put it in finally block. } ; ; ; ;