Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/117/mutex

A mutex implementation for Deno that supports async/await.
https://github.com/117/mutex

async await deno lock mutex

Last synced: about 1 month ago
JSON representation

A mutex implementation for Deno that supports async/await.

Awesome Lists containing this project

README

        

# mutex

![version](https://img.shields.io/jsr/v/%40117/mutex?style=flat-square&color=%23ff51bc&label=version)
![status](https://img.shields.io/github/actions/workflow/status/117/mutex/deploy.yml?style=flat-square)

A mutex implementation for Deno that supports async/await.

## Contents

- [Features](#features)
- [Install](#install)
- [Example](#example)
- [Contributing](#contributing)

## Features

- [x] Simple and lightweight.
- [x] Controls access to code that should run synchronously.

## Install

For Deno:

```sh
$ deno add @117/mutex
```

## Example

```ts
import { createMutex } from "@117/mutex";

const mutex = createMutex();

const work = async () => {
await mutex.acquire();

try {
console.log("mutex acquired, doing work");
} finally {
mutex.release();
}
};

// they will not run concurrently
await Promise.all([work(), work()]);
```

## Contributing

Feel free to contribute and PR to your 💖's content.