Mutex and Semaphore for JavaScript


Summary of my bookmarked links and Github repositories from Sep 21st, 2023

Links

  • DE2900455A1

    This patent describes a method for cultivating mycorrhiza fungi, specifically Boletus edulis, using an exchange-surface system with permeable membranes or capillaries. Nutrient solution and metabolites are supplied and removed separately from the container, and the system allows for the alteration of nutrient composition and gas atmosphere. The method can be used for growing edible mushrooms, mimicking their natural conditions.

Github repositories

  • DirtyHairy/async-mutex

    This JavaScript library, called "async-mutex," provides synchronization primitives for managing asynchronous operations. It offers two main components: Mutex and Semaphore. **Mutex**: - Mutex is used to synchronize concurrent processes in single-threaded JavaScript. - It helps prevent race conditions by providing exclusive access to a resource. - You can create a new mutex and execute code exclusively using `runExclusive` or manually acquire and release the mutex with `acquire`. **Semaphore**: - Semaphores are used to control access to shared resources among multiple processes. - They can be initialized with an arbitrary integer value and support locking multiple times. - `runExclusive` with a semaphore allows controlled access to a resource. - You can also manually acquire and release semaphores using `acquire`. **How to Use**: - The library is available via npm and supports TypeScript. - You can import Mutex and Semaphore in various ways depending on your environment. **Cancelling Pending Locks**: - You can cancel pending locks with `cancel()` on both Mutex and Semaphore. **Waiting for Unlock**: - You can wait until a Mutex or Semaphore is available without locking it using `waitForUnlock()`. **Timeouts**: - The library supports timeout functionality using `withTimeout` to limit waiting times for Mutex and Semaphore. - It also provides a way to fail early with `tryAcquire` if the resource is not available. This library is released under the MIT license, making it open for use in your projects. "async-mutex" is a JavaScript library that offers Mutex and Semaphore for managing asynchronous operations, preventing race conditions, and controlling resource access. It supports timeouts and is available under the MIT license.