Copyright | Copyright (c) 2009-2017 David Sorokin <david.sorokin@gmail.com> |
---|---|

License | BSD3 |

Maintainer | David Sorokin <david.sorokin@gmail.com> |

Stability | experimental |

Safe Haskell | None |

Language | Haskell2010 |

## Synopsis

- data ContCancellation
- data ContId
- data ContEvent
- newtype Cont a = Cont (ContParams a -> Event ())
- data ContParams a
- data FrozenCont a
- newContId :: Simulation ContId
- contSignal :: ContId -> Signal ContEvent
- contCancellationInitiated :: ContId -> Event Bool
- contCancellationInitiate :: ContId -> Event ()
- contCancellationInitiating :: ContId -> Signal ()
- contCancellationActivated :: ContId -> IO Bool
- contCancellationBind :: ContId -> [ContId] -> Event DisposableEvent
- contCancellationConnect :: ContId -> ContCancellation -> ContId -> Event DisposableEvent
- contPreemptionBegun :: ContId -> Event Bool
- contPreemptionBegin :: ContId -> Event ()
- contPreemptionBeginning :: ContId -> Signal ()
- contPreemptionEnd :: ContId -> Event ()
- contPreemptionEnding :: ContId -> Signal ()
- invokeCont :: ContParams a -> Cont a -> Event ()
- runCont :: Cont a -> (a -> Event ()) -> (SomeException -> Event ()) -> (() -> Event ()) -> ContId -> Bool -> Event ()
- rerunCont :: Cont a -> ContId -> Cont a
- spawnCont :: ContCancellation -> Cont () -> ContId -> Cont ()
- contParallel :: [(Cont a, ContId)] -> Cont [a]
- contParallel_ :: [(Cont a, ContId)] -> Cont ()
- catchCont :: Exception e => Cont a -> (e -> Cont a) -> Cont a
- finallyCont :: Cont a -> Cont b -> Cont a
- throwCont :: Exception e => e -> Cont a
- resumeCont :: ContParams a -> a -> Event ()
- resumeECont :: ContParams a -> SomeException -> Event ()
- reenterCont :: ContParams a -> a -> Event ()
- freezeCont :: ContParams a -> Event (FrozenCont a)
- freezeContReentering :: ContParams a -> a -> Event () -> Event (FrozenCont a)
- unfreezeCont :: FrozenCont a -> Event (Maybe (ContParams a))
- substituteCont :: ContParams a -> (a -> Event ()) -> ContParams a
- contCanceled :: ContParams a -> IO Bool
- contAwait :: Signal a -> Cont a
- transferCont :: Cont () -> Cont a
- traceCont :: String -> Cont a -> Cont a

# Documentation

data ContCancellation Source #

It defines how the parent and child computations should be cancelled.

CancelTogether | Cancel the both computations together. |

CancelChildAfterParent | Cancel the child if its parent is cancelled. |

CancelParentAfterChild | Cancel the parent if its child is cancelled. |

CancelInIsolation | Cancel the computations in isolation. |

It identifies the `Cont`

computation.

The event that occurs within the `Cont`

computation.

ContCancellationInitiating | Cancel the computation. |

ContPreemptionBeginning | Preempt the computation. |

ContPreemptionEnding | Proceed with the computation after if was preempted. |

The `Cont`

type is similar to the standard `Cont`

monad
and F# async workflow but only the result of applying
the continuations return the `Event`

computation.

Cont (ContParams a -> Event ()) |

#### Instances

Monad Cont Source # | |

Functor Cont Source # | |

Applicative Cont Source # | |

MonadIO Cont Source # | |

Defined in Simulation.Aivika.Internal.Cont | |

MonadThrow Cont Source # | |

Defined in Simulation.Aivika.Internal.Cont | |

MonadCatch Cont Source # | |

ParameterLift Cont Source # | |

Defined in Simulation.Aivika.Internal.Cont liftParameter :: Parameter a -> Cont a Source # | |

SimulationLift Cont Source # | |

Defined in Simulation.Aivika.Internal.Cont liftSimulation :: Simulation a -> Cont a Source # | |

DynamicsLift Cont Source # | |

Defined in Simulation.Aivika.Internal.Cont liftDynamics :: Dynamics a -> Cont a Source # | |

EventLift Cont Source # | |

data ContParams a Source #

The continuation parameters.

data FrozenCont a Source #

Represents a temporarily frozen computation.

newContId :: Simulation ContId Source #

Create a computation identifier.

contCancellationInitiate :: ContId -> Event () Source #

Initiate the cancellation.

contCancellationInitiating :: ContId -> Signal () Source #

Signal when the cancellation is intiating.

contCancellationBind :: ContId -> [ContId] -> Event DisposableEvent Source #

If the main computation is cancelled then all the nested ones will be cancelled too.

contCancellationConnect Source #

:: ContId | the parent |

-> ContCancellation | how to connect |

-> ContId | the child |

-> Event DisposableEvent | computation of the disposable handler |

Connect the parent computation to the child one.

contPreemptionBegin :: ContId -> Event () Source #

Preempt the computation.

contPreemptionBeginning :: ContId -> Signal () Source #

Signal when the computation is preempted.

contPreemptionEnd :: ContId -> Event () Source #

Proceed with the computation after it was preempted earlier.

contPreemptionEnding :: ContId -> Signal () Source #

Signal when the computation is proceeded after it was preempted before.

invokeCont :: ContParams a -> Cont a -> Event () Source #

Invoke the computation.

:: Cont a | the computation to run |

-> (a -> Event ()) | the main branch |

-> (SomeException -> Event ()) | the branch for handing exceptions |

-> (() -> Event ()) | the branch for cancellation |

-> ContId | the computation identifier |

-> Bool | whether to support the exception handling from the beginning |

-> Event () |

Run the `Cont`

computation with the specified cancelation source
and flag indicating whether to catch exceptions from the beginning.

rerunCont :: Cont a -> ContId -> Cont a Source #

Rerun the `Cont`

computation with the specified identifier.

spawnCont :: ContCancellation -> Cont () -> ContId -> Cont () Source #

Run the `Cont`

computation in parallel but connect the computations.

Execute the specified computations in parallel within the current computation and return their results. The cancellation of any of the nested computations affects the current computation. The exception raised in any of the nested computations is propogated to the current computation as well (if the exception handling is supported).

Here word `parallel`

literally means that the computations are
actually executed on a single operating system thread but
they are processed simultaneously by the event queue.

A partial case of `contParallel`

when we are not interested in
the results but we are interested in the actions to be peformed by
the nested computations.

catchCont :: Exception e => Cont a -> (e -> Cont a) -> Cont a Source #

Exception handling within `Cont`

computations.

throwCont :: Exception e => e -> Cont a Source #

Throw the exception with the further exception handling.

By some reason, an exception raised with help of the standard `throw`

function
is not handled properly within `Cont`

computation, altough it will be still handled
if it will be wrapped in the `IO`

monad. Therefore, you should use specialised
functions like the stated one that use the `throw`

function but within the `IO`

computation,
which allows already handling the exception.

resumeCont :: ContParams a -> a -> Event () Source #

Resume the computation by the specified parameters.

resumeECont :: ContParams a -> SomeException -> Event () Source #

Resume the exception handling by the specified parameters.

reenterCont :: ContParams a -> a -> Event () Source #

Reenter the computation parameters when needed.

freezeCont :: ContParams a -> Event (FrozenCont a) Source #

Freeze the computation parameters temporarily.

freezeContReentering :: ContParams a -> a -> Event () -> Event (FrozenCont a) Source #

Freeze the computation parameters specifying what should be done when reentering the computation.

unfreezeCont :: FrozenCont a -> Event (Maybe (ContParams a)) Source #

Unfreeze the computation.

substituteCont :: ContParams a -> (a -> Event ()) -> ContParams a Source #

Substitute the continuation.

contCanceled :: ContParams a -> IO Bool Source #

Test whether the computation is canceled.

transferCont :: Cont () -> Cont a Source #

Like the GoTo statement it transfers the direction of computation,
but raises an exception when used within `catchCont`

or `finallyCont`

.