Documentation

Hale.Base.Control.Concurrent.QSemN

A generalised quantity semaphore. Allows acquiring and releasing arbitrary amounts of the resource.

$$\text{QSemN.new} : \text{Nat} \to \text{BaseIO}\ \text{QSemN}$$

Modelled after Haskell's QSemN.

Instances For

    Create a new semaphore with the given initial count.

    $$\text{new} : \text{Nat} \to \text{BaseIO}\ \text{QSemN}$$

    Equations
    Instances For

      Acquire $n$ units. If insufficient units are available, the caller becomes a dormant promise until enough are released.

      $$\text{wait} : \text{QSemN} \to \text{Nat} \to \text{BaseIO}\ (\text{Task}\ \text{Unit})$$

      Equations
      • One or more equations did not get rendered due to their size.
      Instances For

        Release $n$ units. Wakes as many FIFO-ordered waiters as the available count allows.

        $$\text{signal} : \text{QSemN} \to \text{Nat} \to \text{BaseIO}\ \text{Unit}$$

        Equations
        • One or more equations did not get rendered due to their size.
        Instances For
          def Control.Concurrent.QSemN.withSemN {α : Type} (sem : QSemN) (n : Nat) (action : IO α) :
          IO α

          Acquire $n$ units, run an action, then release $n$ — even if the action throws. Guarantees the semaphore is released via try/finally.

          $$\text{withSemN} : \text{QSemN} \to \mathbb{N} \to \text{IO}\ \alpha \to \text{IO}\ \alpha$$

          Equations
          Instances For