Copyright | (c) Ivan Perez 2014-2024 (c) George Giorgidze 2007-2012 (c) Henrik Nilsson 2005-2006 (c) Antony Courtney and Henrik Nilsson Yale University 2003-2004 |
---|---|
License | BSD3 |
Maintainer | ivan.perez@keera.co.uk |
Stability | provisional |
Portability | non-portable (GHC extensions) |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
FRP.BearRiver.Task
Description
Task abstraction on top of signal transformers.
Synopsis
- data Task m a b c
- mkTask :: Monad m => SF m a (b, Event c) -> Task m a b c
- runTask :: Monad m => Task m a b c -> SF m a (Either b c)
- runTask_ :: Monad m => Task m a b c -> SF m a b
- taskToSF :: Monad m => Task m a b c -> SF m a (b, Event c)
- constT :: Monad m => b -> Task m a b c
- sleepT :: Monad m => Time -> b -> Task m a b ()
- snapT :: Monad m => Task m a b a
- timeOut :: Monad m => Task m a b c -> Time -> Task m a b (Maybe c)
- abortWhen :: Monad m => Task m a b c -> SF m a (Event d) -> Task m a b (Either c d)
The Task type
A task is a partially SF that may terminate with a result.
runTask :: Monad m => Task m a b c -> SF m a (Either b c) Source #
Runs a task.
The output from the resulting signal transformer is tagged with Left while the underlying task is running. Once the task has terminated, the output goes constant with the value Right x, where x is the value of the terminating event.
runTask_ :: Monad m => Task m a b c -> SF m a b Source #
Runs a task that never terminates.
The output becomes undefined once the underlying task has terminated.
Convenience function for tasks which are known not to terminate.
taskToSF :: Monad m => Task m a b c -> SF m a (b, Event c) Source #
Creates an SF that represents an SF and produces an event when the task terminates, and otherwise produces just an output.
Basic tasks
sleepT :: Monad m => Time -> b -> Task m a b () Source #
Sleeps for t seconds with constant output b.
snapT :: Monad m => Task m a b a Source #
Takes a "snapshot" of the input and terminates immediately with the input value as the result.
No time passes; therefore, the following must hold:
snapT >> snapT = snapT
Basic tasks combinators
timeOut :: Monad m => Task m a b c -> Time -> Task m a b (Maybe c) infixl 0 Source #
Impose a time out on a task.
abortWhen :: Monad m => Task m a b c -> SF m a (Event d) -> Task m a b (Either c d) infixl 0 Source #
Run a "guarding" event source (SF m a (Event b)) in parallel with a (possibly non-terminating) task.
The task will be aborted at the first occurrence of the event source (if it has not terminated itself before that).
Useful for separating sequencing and termination concerns. E.g. we can do something "useful", but in parallel watch for a (exceptional) condition which should terminate that activity, without having to check for that condition explicitly during each and every phase of the activity.
Example: tsk
abortWhen
lbp