Module Fut.Sem
Semaphores for limiting resource usage.
TODO doc.
Semaphores
type 'a future
= 'a t
type token
The type for tokens.
val create : capacity:int -> t
create capacity
is a semaphore with a token capacity ofcapacity
.
val capacity : t -> int
capacity s
iss
's token capacity.
val available : t -> int
available s
iss
'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
, decrementsavailable s
and determines a token immediately. - Otherwise determines when
available s
becomes> 0
and all previous futures resulting fromtake s
have been set (i.e. you are served in FIFO order).
- If at call time