Copyright | Copyright (c) 2009-2017 David Sorokin <david.sorokin@gmail.com> |
---|---|
License | BSD3 |
Maintainer | David Sorokin <david.sorokin@gmail.com> |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Tested with: GHC 8.0.1
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
- data Task m a
- data TaskResult a
- taskId :: Task m a -> ProcessId m
- tryGetTaskResult :: MonadDES m => Task m a -> Event m (Maybe (TaskResult a))
- taskResult :: MonadDES m => Task m a -> Process m (TaskResult a)
- taskResultReceived :: Task m a -> Signal m (TaskResult a)
- taskProcess :: MonadDES m => Task m a -> Process m a
- cancelTask :: MonadDES m => Task m a -> Event m ()
- taskCancelled :: MonadDES m => Task m a -> Event m Bool
- runTask :: MonadDES m => Process m a -> Event m (Task m a)
- runTaskUsingId :: MonadDES m => ProcessId m -> Process m a -> Event m (Task m a)
- spawnTask :: MonadDES m => Process m a -> Process m (Task m a)
- spawnTaskUsingId :: MonadDES m => ProcessId m -> Process m a -> Process m (Task m a)
- spawnTaskWith :: MonadDES m => ContCancellation -> Process m a -> Process m (Task m a)
- spawnTaskUsingIdWith :: MonadDES m => ContCancellation -> ProcessId m -> Process m a -> Process m (Task m a)
- enqueueTask :: MonadDES m => Double -> Process m a -> Event m (Task m a)
- enqueueTaskUsingId :: MonadDES m => Double -> ProcessId m -> Process m a -> Event m (Task m a)
- taskParallelResult :: MonadDES m => Task m a -> Task m a -> Process m (TaskResult a, Task m a)
- taskParallelProcess :: MonadDES m => Task m a -> Task m a -> Process m (a, Task m a)
Task
data TaskResult a Source #
Represents the result of the task.
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 :: MonadDES m => Task m a -> Event m (Maybe (TaskResult a)) Source #
Try to get the task result immediately without suspension.
taskResult :: MonadDES 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 :: MonadDES m => Task m a -> Process m a Source #
Return an outer process that behaves like the task itself, for example, when the task is cancelled if the outer process is cancelled.
taskCancelled :: MonadDES m => Task m a -> Event m Bool Source #
Test whether the task was cancelled.
Running Task
runTask :: MonadDES m => Process m a -> Event m (Task m a) Source #
Run the process in background and return the corresponding task immediately.
runTaskUsingId :: MonadDES m => ProcessId m -> Process m a -> Event m (Task m a) Source #
Run the process with the specified identifier in background and return the corresponding task immediately.
Spawning Tasks
spawnTask :: MonadDES m => Process m a -> Process m (Task m a) Source #
Run a child process in background and return immediately the corresponding task.
spawnTaskUsingId :: MonadDES 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 corresponding task.
spawnTaskWith :: MonadDES m => ContCancellation -> Process m a -> Process m (Task m a) Source #
Run a child process in background and return immediately the corresponding task.
spawnTaskUsingIdWith :: MonadDES 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 corresponding task.
Enqueueing Task
enqueueTask :: MonadDES 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 corresponding task immediately.
enqueueTaskUsingId :: MonadDES 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 corresponding task immediately.
Parallel Tasks
taskParallelResult :: MonadDES m => Task m a -> Task m a -> Process m (TaskResult a, Task m a) Source #
Return the result of two parallel tasks.