locksmanager
TypeScript icon, indicating that this package has built-in type declarations

1.4.3 • Public • Published

locks manager

an fully lock api for one-master, one-master-with-multi-cluster.

flow (Single process)

lm = new LocksManager();
 |
lm.appendLock(ids:string[])
 |
(find PER locks by ids. and add ids as CUR locks)
 |
(return locksRef)
 |
await locksRef.getPreJobsDone()
 |
(await Promise.all(PER locks))
 |
...do your jobs
 |
lm.finishAll()
 |
(each CUR locks do unlock. => promise.resolve() )

multi-Progress

there have an default lm in master process. and child process will share this lm.

in master process:

import { registerLocksManagerDefaultValueGetter } from 'locksmanager';
// register an value getter function. and also setup.
// or may be just return undefined. it's ok. save the ipc.
registerLocksManagerDefaultValueGetter(async (lock_id)=>{
    const model = await db.getById(lock_id);
    const {
        ignore_pro_A,
        ignore_pro_B,
        ...filtered_fields
    } = model;
    return filtered_fields;
});

in cluster(worker) process:

import { ClusterLocksManager } from 'locksmanager';
const lm = new ClusterLocksManager();
await lm.appendLock(ids as string[]);
await lm.getPreJobsDone();
// do your jobs
lm.finishAll();

Readme

Keywords

none

Package Sidebar

Install

npm i locksmanager

Weekly Downloads

1

Version

1.4.3

License

MIT

Unpacked Size

170 kB

Total Files

25

Last publish

Collaborators

  • kezhaofeng