Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yooneskh/unified-deno-lock
Simple lock (mutex) solution for deno
https://github.com/yooneskh/unified-deno-lock
Last synced: 25 days ago
JSON representation
Simple lock (mutex) solution for deno
- Host: GitHub
- URL: https://github.com/yooneskh/unified-deno-lock
- Owner: yooneskh
- Created: 2022-04-22T20:24:58.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2022-04-23T16:30:41.000Z (over 2 years ago)
- Last Synced: 2024-08-04T00:06:18.597Z (4 months ago)
- Language: TypeScript
- Size: 1.95 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-deno - unified-deno-lock - Powerful and simple lock (mutex) library to handle race conditions with zero dependencies (Modules / Utils)
README
# Unified Deno Lock
This is a simple and powerful module with zero dependencies, which you can use as a mutex to control race conditions. At its core, this library uses promises to create locks, and everyone then has to wait until the promise is resolved to be able to go forward.## Usage
You can look at the `./test/lock_test.ts` for usage samples, But basically this is how the locks are used.```ts
import { Lock } from 'https://deno.land/x/unified_deno_lock/mod.ts';const myResourceLock = new Lock();
function initializeResource() {
myResourceLock.lock();
// do initializations
myResourceLock.unlock();
}
async function useResource() {
await myResourceLock.knock(); // waits at this line until lock is unlocked
// work with the initialized resource
}
```*Note:* This is not a complete mutex solution that handles every problem in that domain. Although, with this basic lock, you should be able to handle those scenarios.
## Tests
Run tests with `deno test` or with `deno test --watch` to watch for file changes.## Licence
[MIT](https://opensource.org/licenses/MIT)