time-out-0.2: Timers, timeouts, alarms, monadic wrappers

Safe HaskellNone
LanguageHaskell2010

Control.Monad.Timeout.Class

Description

A typeclass for monads which can run actions with a time limit.

Synopsis

Documentation

data Timeout Source

Timeout exception. Thrown when an action is executed with a time limit, and the time passes before the action finishes.

Constructors

Timeout 

class (Monad p, Monad m) => MonadTimeout m p where Source

A class for monads capable of executing computations with a time limit. This class provides a uniform interface to the various possible implementations.

For example, a trivial implementation may launch a helper thread for each time-limited action. A more scalable implementation, preferred for some cases, may keep a single dedicated thread and reuse it instead of starting new ones.

Methods

timeoutThrow :: TimeUnit t => t -> p a -> m a Source

Execute an action with a time limit. If the action finishes before the given time passes, return the value it returned. If the time passes and the action hasn't finished yet, throw a Timeout exception.

timeoutCatch :: TimeUnit t => t -> p a -> m (Maybe a) Source

Execute an action with a time limit. If the action finishes before the given time passes, return Just the value it returned. If the time passes and the action hasn't finished yet, return Nothing.

Instances