Stability | experimental |
---|---|
Maintainer | David Sorokin <david.sorokin@gmail.com> |
Safe Haskell | Safe-Inferred |
Tested with: GHC 7.6.3
The module defines the Event
monad which is very similar to the Dynamics
monad but only now the computation is strongly synchronized with the event queue.
- data Event a
- class Monad m => EventLift m where
- data EventProcessing
- data EventCancellation = EventCancellation {
- cancelEvent :: Event ()
- eventCanceled :: Event Bool
- eventFinished :: Event Bool
- runEvent :: EventProcessing -> Event a -> Dynamics a
- runEventInStartTime :: EventProcessing -> Event a -> Simulation a
- runEventInStopTime :: EventProcessing -> Event a -> Simulation a
- enqueueEvent :: Double -> Event () -> Event ()
- enqueueEventWithCancellation :: Double -> Event () -> Event EventCancellation
- enqueueEventWithTimes :: [Double] -> Event () -> Event ()
- enqueueEventWithIntegTimes :: Event () -> Event ()
- enqueueEventWithStartTime :: Event () -> Event ()
- enqueueEventWithStopTime :: Event () -> Event ()
- enqueueEventWithCurrentTime :: Event () -> Event ()
- eventQueueCount :: Event Int
- catchEvent :: Event a -> (IOException -> Event a) -> Event a
- finallyEvent :: Event a -> Event b -> Event a
- throwEvent :: IOException -> Event a
Event Monad
A value in the Event
monad represents a polymorphic time varying function
which is strongly synchronized with the event queue.
data EventProcessing Source
Defines how the events are processed.
IncludingCurrentEvents | either process all earlier and then current events, or raise an error if the current simulation time is less than the actual time of the event queue |
IncludingEarlierEvents | either process all earlier events not affecting the events at the current simulation time, or raise an error if the current simulation time is less than the actual time of the event queue |
IncludingCurrentEventsOrFromPast | either process all earlier and then current events, or do nothing if the current simulation time is less than the actual time of the event queue (do not use unless the documentation states the opposite) |
IncludingEarlierEventsOrFromPast | either process all earlier events, or do nothing if the current simulation time is less than the actual time of the event queue (do not use unless the documentation states the opposite) |
data EventCancellation Source
It allows cancelling the event.
EventCancellation | |
|
runEvent :: EventProcessing -> Event a -> Dynamics aSource
runEventInStartTime :: EventProcessing -> Event a -> Simulation aSource
Run the Event
computation in the start time.
runEventInStopTime :: EventProcessing -> Event a -> Simulation aSource
Run the Event
computation in the stop time.
Event Queue
enqueueEvent :: Double -> Event () -> Event ()Source
Enqueue the event which must be actuated at the specified time.
The events are processed when calling the runEvent
function. So,
if you want to insist on their immediate execution then you can apply
something like
liftDynamics $ runEvent IncludingCurrentEvents $ return ()
although this is generally not good idea.
enqueueEventWithCancellation :: Double -> Event () -> Event EventCancellationSource
Enqueue the event with an ability to cancel it.
enqueueEventWithTimes :: [Double] -> Event () -> Event ()Source
Actuate the event handler in the specified time points.
enqueueEventWithIntegTimes :: Event () -> Event ()Source
Actuate the event handler in the integration time points.
enqueueEventWithStartTime :: Event () -> Event ()Source
Actuate the event handler in the start time.
enqueueEventWithStopTime :: Event () -> Event ()Source
Actuate the event handler in the stop time.
enqueueEventWithCurrentTime :: Event () -> Event ()Source
Actuate the event handler in the current time but through the event queue, which allows continuing the current tasks and then calling the handler after the tasks are finished. The simulation time will be the same.
eventQueueCount :: Event IntSource
Return the number of pending events that should be yet actuated.
Error Handling
catchEvent :: Event a -> (IOException -> Event a) -> Event aSource
Exception handling within Event
computations.
finallyEvent :: Event a -> Event b -> Event aSource
A computation with finalization part like the finally
function.
throwEvent :: IOException -> Event aSource
Like the standard throw
function.