Module Fut.Sem

Semaphores for limiting resource usage.

TODO doc.

Semaphores

type 'a future = 'a t
type token

The type for tokens.

type t

The type for semaphores.

val create : capacity:int -> t

create capacity is a semaphore with a token capacity of capacity.

val capacity : t -> int

capacity s is s's token capacity.

val available : t -> int

available s is s's number of available tokens.

val take : t -> token future

take s is a future that determines as follows:

  • If at call time available s > 0, decrements available s and determines a token immediately.
  • Otherwise determines when available s becomes > 0 and all previous futures resulting from take s have been set (i.e. you are served in FIFO order).
val return : t -> token -> unit

return s token returns the token token to s. As a side effect, determines the first non set take s future waiting (if any).

raises Invalid_argument

if token was already returned or if token doesn't belong to s.