@hazae41/mutex
TypeScript icon, indicating that this package has built-in type declarations

1.2.12 • Public • Published

Mutex

Rust-like Mutex for TypeScript

npm i @hazae41/mutex

Node Package 📦

Features

Current features

  • 100% TypeScript and ESM
  • No external dependencies
  • Similar to Rust
  • Can hold data
  • Unit-tested
  • Uses Result from @hazae41/result

Usage

import { Mutex } from "@hazae41/mutex"

const mutex = new Mutex(123)

async function first() {
  await mutex.lock(async (x) => {
    // do stuff with x
  })
}

async function second() {
  await mutex.lock(async (x) => {
    // do stuff with x
  })
}

async function third() {
  await mutex.tryLock(async (x) => {
    // do stuff with x
  }).unwrap()
}

first()
second()
third()

Package Sidebar

Install

npm i @hazae41/mutex

Weekly Downloads

112

Version

1.2.12

License

MIT

Unpacked Size

16.7 kB

Total Files

13

Last publish

Collaborators

  • hazae41