aivika-transformers-2.1: Transformers for the Aivika simulation library

CopyrightCopyright (c) 2009-2014, David Sorokin <david.sorokin@gmail.com>
LicenseBSD3
MaintainerDavid Sorokin <david.sorokin@gmail.com>
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010

Simulation.Aivika.Trans.Task

Contents

Description

Tested with: GHC 7.8.3

The Task value represents a process that was already started in background. We can check the completion of the task, receive notifications about changing its state and even suspend an outer process awaiting the final result of the task. It complements the Process monad as it allows immediately continuing the main computation without suspension.

Synopsis

Task

data Task m a Source

The task represents a process that was already started in background.

data TaskResult a Source

Represents the result of the task.

Constructors

TaskCompleted a

the task was successfully completed and it returned the specified result

TaskError SomeException

the specified exception was raised when performing the task.

TaskCancelled

the task was cancelled

taskId :: Task m a -> ProcessId m Source

Return an identifier for the process that was launched in background for this task.

tryGetTaskResult :: MonadComp m => Task m a -> Event m (Maybe (TaskResult a)) Source

Try to get the task result immediately without suspension.

taskResult :: MonadComp m => Task m a -> Process m (TaskResult a) Source

Return the task result suspending the outer process if required.

taskResultReceived :: Task m a -> Signal m (TaskResult a) Source

Return a signal that notifies about receiving the result of the task.

taskProcess :: MonadComp m => Task m a -> Process m a Source

Return an outer process that behaves like the task itself except for one thing: if the outer process is cancelled then it is not enough to cancel the task.

cancelTask :: MonadComp m => Task m a -> Event m () Source

Cancel the task.

taskCancelled :: MonadComp m => Task m a -> Event m Bool Source

Test whether the task was cancelled.

Running Task

runTask :: MonadComp m => Process m a -> Event m (Task m a) Source

Run the process in background and return the corresponded task immediately.

runTaskUsingId :: MonadComp m => ProcessId m -> Process m a -> Event m (Task m a) Source

Run the process with the specified identifier in background and return the corresponded task immediately.

Spawning Tasks

spawnTask :: MonadComp m => Process m a -> Process m (Task m a) Source

Run a child process in background and return immediately the corresponded task.

spawnTaskUsingId :: MonadComp m => ProcessId m -> Process m a -> Process m (Task m a) Source

Run using the specified identifier a child process in background and return immediately the corresponded task.

spawnTaskWith :: MonadComp m => ContCancellation -> Process m a -> Process m (Task m a) Source

Run a child process in background and return immediately the corresponded task.

spawnTaskUsingIdWith :: MonadComp m => ContCancellation -> ProcessId m -> Process m a -> Process m (Task m a) Source

Run using the specified identifier a child process in background and return immediately the corresponded task.

Enqueueing Task

enqueueTask :: MonadComp m => Double -> Process m a -> Event m (Task m a) Source

Enqueue the process that will be started at the specified time from the event queue. It returns the corresponded task immediately.

enqueueTaskUsingId :: MonadComp m => Double -> ProcessId m -> Process m a -> Event m (Task m a) Source

Enqueue the process that will be started at the specified time with the given identifier from the event queue. It returns the corresponded task immediately.