hyperion-0.1.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Hyperion.TokenPool

Synopsis

Documentation

newtype TokenPool Source #

A TokenPool keeps track of the number of resources of some kind, represented by "tokens". 'TokenPool (Just var)' indicates a limited number of tokens, and var contains the number of available tokens. When var contains 0, processes wishing to use a token must block until one becomes available (see withToken). 'TokenPool Nothing' represents an unlimited number of tokens.

Constructors

TokenPool (Maybe (TVar Int)) 

newTokenPool :: Maybe Int -> IO TokenPool Source #

Create a new TokenPool containing the given number of tokens. Nothing indicates an unlimited pool.

withToken :: (MonadIO m, MonadMask m) => TokenPool -> m a -> m a Source #

Remove a token from the pool, run the given process, and then replace the token. If no token is initially available, block until one becomes available.