Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
mortice
Advanced tools
Readme
Isomorphic read/write lock that works in single processes, node clusters and web workers
import mortice from 'mortice'
import delay from 'delay'
// the lock name & options objects are both optional
const mutex = mortice('my-lock', {
// how long before write locks time out (default: 24 hours)
timeout: 30000,
// control how many read operations are executed concurrently (default: Infinity)
concurrency: 5,
// by default the the lock will be held on the main thread, set this to true if the
// a lock should reside on each worker (default: false)
singleProcess: false
})
Promise.all([
(async () => {
const release = await mutex.readLock()
try {
console.info('read 1')
} finally {
release()
}
})(),
(async () => {
const release = await mutex.readLock()
try {
console.info('read 2')
} finally {
release()
}
})(),
(async () => {
const release = await mutex.writeLock()
try {
await delay(1000)
console.info('write 1')
} finally {
release()
}
})(),
(async () => {
const release = await mutex.readLock()
try {
console.info('read 3')
} finally {
release()
}
})()
])
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 observable-webworkers
module:
// main.js
import mortice from 'mortice'
import observe from 'observable-webworkers'
// create our lock on the main thread, it will be held here
const mutex = mortice()
const worker = new Worker('worker.js')
observe(worker)
// worker.js
import mortice from 'mortice'
import delay from 'delay'
const mutex = mortice()
let release = await mutex.readLock()
// read something
release()
release = await mutex.writeLock()
// write something
release()
$ npm i mortice
<script>
tagLoading this module through a script tag will make it's exports available as Mortice
in the global namespace.
<script src="https://unpkg.com/mortice/dist/index.min.js"></script>
Licensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
FAQs
Isomorphic read/write lock that works in single processes, node clusters and web workers
The npm package mortice receives a total of 10,608 weekly downloads. As such, mortice popularity was classified as popular.
We found that mortice demonstrated a healthy version release cadence and project activity because the last version was released less than 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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.