mortice1.2.1 • Public • Published
Isomorphic read/write lock that works in single processes, node clusters and web workers.
- Reads occur concurrently
- Writes occur one at a time
- No reads occur while a write operation is in progress
- Locks can be created with different names
- Reads/writes can time out
$ npm install --save mortice
const mortice =const delay =// the lock name & options objects are both optionalconst mutex =mutexmutexmutexmutex
read 1 read 2 <small pause> write 1 read 3
Because there's no global way to evesdrop on messages sent by Web Workers, please pass all created Web Workers to the
// main.jsconst mortice =const observe =// create our lock on the main thread, it will be held hereconst mutex =const worker = 'worker.js'
// worker.jsconst mortice =const delay =const mutex =mutexmutex
Alternatively you can use the bundled
mortice.Worker to create web workers and save yourself an extra dependency.
const mortice =const Worker = morticeWorker// create our lock on the main thread, it will be held hereconst mutex =const worker = 'worker.js'