Contents

Description

The operations for MonadTask are similar to those of co-routines, with the addition of watching and signaling events.

We also define a set of auto lifting for common transformers. Note that we purposely leave a case undefined where a state transformer goes on top of a task monad, because such an operation is either unsound or has to roll back the state (see liftCallCC). So it's recommended to keep TaskT on top of all StateT in a transformer stack.

Synopsis

MonadTask specifies a task monad m over an event type e.

Minimal complete definition

Methods

yield :: m () Source #

yield temporarily suspends current task to let others run.

fork :: m a -> m () Source #

fork spawns a task and runs it immediately until it ends or suspends before returning to current task.

watch :: (e -> Maybe a) -> m a Source #

watch suspends the current task to wait for future events, and will resume execution when an event triggers its watching function.

signal :: e -> m () Source #

signal broadcasts an event to all other tasks that are watching, and give those who wake up the priority to run.

exit :: m () Source #

exit ends all tasks and returns immediately.

Instances

orElse is a helper function for combining two trigger functions disjuctively, favoring the first one.