moonbitlang/async/semaphore does not have a README file

    Semaphore

    type Semaphore

    Semaphore::acquire

    async fn Semaphore::acquire(self : Semaphore) -> Unit

    Acquire one unit of resource from the semaphore. If no resource is available, acquire will block and wait until any resource is available. If there are multiple tasks both waiting for the same resource, new resource will be delivered in a first-come-first-serve manner.

    acquire itself never fail, and will wait indefinitely. However, since acquire is a blocking point, the task running acquire may be cancelled, in this case, an cancellation will be raised from acquire.

    Semaphore::new

    fn Semaphore::new(size : Int, initial_value? : Int) -> Semaphore

    Create a semaphore of size size, the initial value of the semaphore will be set to initial_value (size by default)

    Semaphore::release

    fn Semaphore::release(self : Semaphore) -> Unit

    Release a unit of resource back to the semaphore. This function never blocks. If there are waiters currently blocked on the semaphore, the first waiter will be woken to acquire the resource.

    release must be called after a successful acquire, in strictly one-to-one manner. If the value of the semaphore exceed its size, release will abort immediately.

    Semaphore::try_acquire

    fn Semaphore::try_acquire(self : Semaphore) -> Bool

    Try to acquire one unit of resource from the semaphore. If resource is successfully acquired, true is returned, Otherwise, false is returned immediately without blocking.

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io