a really simple mutex jsr.io/@mary/mutex
typescript jsr
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

initial commit

Mary 084c08de

+109
+4
.vscode/settings.json
··· 1 + { 2 + "editor.defaultFormatter": "denoland.vscode-deno", 3 + "deno.enable": true 4 + }
+40
.zed/settings.json
··· 1 + { 2 + "lsp": { 3 + "deno": { 4 + "settings": { 5 + "deno": { 6 + "enable": true 7 + } 8 + } 9 + } 10 + }, 11 + "languages": { 12 + "JavaScript": { 13 + "language_servers": [ 14 + "deno", 15 + "!typescript-language-server", 16 + "!vtsls", 17 + "!eslint" 18 + ], 19 + "formatter": "language_server" 20 + }, 21 + "TypeScript": { 22 + "language_servers": [ 23 + "deno", 24 + "!typescript-language-server", 25 + "!vtsls", 26 + "!eslint" 27 + ], 28 + "formatter": "language_server" 29 + }, 30 + "TSX": { 31 + "language_servers": [ 32 + "deno", 33 + "!typescript-language-server", 34 + "!vtsls", 35 + "!eslint" 36 + ], 37 + "formatter": "language_server" 38 + } 39 + } 40 + }
+14
LICENSE
··· 1 + BSD Zero Clause License 2 + 3 + Copyright (c) 2025 Mary 4 + 5 + Permission to use, copy, modify, and/or distribute this software for any 6 + purpose with or without fee is hereby granted. 7 + 8 + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 9 + REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 + AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 11 + INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 + LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 13 + OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 + PERFORMANCE OF THIS SOFTWARE.
+13
README.md
··· 1 + # mutex 2 + 3 + a really simple mutex. 4 + 5 + ```ts 6 + const mutex = new Mutex(); 7 + 8 + { 9 + using _lock = await mutex.acquire(); 10 + 11 + // ... go about your day 12 + } 13 + ```
+18
deno.json
··· 1 + { 2 + "name": "@mary/mutex", 3 + "version": "0.1.0", 4 + "license": "0BSD", 5 + "exports": { 6 + ".": "./lib/mod.ts" 7 + }, 8 + "fmt": { 9 + "useTabs": true, 10 + "indentWidth": 2, 11 + "lineWidth": 110, 12 + "semiColons": true, 13 + "singleQuote": true 14 + }, 15 + "publish": { 16 + "include": ["lib/", "LICENSE", "README.md", "deno.json"] 17 + } 18 + }
+20
lib/mod.ts
··· 1 + export interface Lock extends Disposable { 2 + dispose(): void; 3 + } 4 + 5 + class Mutex { 6 + #promise = Promise.resolve(); 7 + 8 + async acquire(): Promise<Lock> { 9 + const { promise, resolve } = Promise.withResolvers<void>(); 10 + 11 + const previous = this.#promise; 12 + 13 + this.#promise = promise; 14 + await previous; 15 + 16 + return { [Symbol.dispose]: resolve, dispose: resolve }; 17 + } 18 + } 19 + 20 + export default Mutex;