Copyright | Copyright (c) 2009-2016 David Sorokin <david.sorokin@gmail.com> |
---|---|
License | BSD3 |
Maintainer | David Sorokin <david.sorokin@gmail.com> |
Stability | experimental |
Safe Haskell | None |
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.
- data Task a
- data TaskResult a
- taskId :: Task a -> ProcessId
- tryGetTaskResult :: Task a -> Event (Maybe (TaskResult a))
- taskResult :: Task a -> Process (TaskResult a)
- taskResultReceived :: Task a -> Signal (TaskResult a)
- taskProcess :: Task a -> Process a
- cancelTask :: Task a -> Event ()
- taskCancelled :: Task a -> Event Bool
- runTask :: Process a -> Event (Task a)
- runTaskUsingId :: ProcessId -> Process a -> Event (Task a)
- spawnTask :: Process a -> Process (Task a)
- spawnTaskUsingId :: ProcessId -> Process a -> Process (Task a)
- spawnTaskWith :: ContCancellation -> Process a -> Process (Task a)
- spawnTaskUsingIdWith :: ContCancellation -> ProcessId -> Process a -> Process (Task a)
- enqueueTask :: Double -> Process a -> Event (Task a)
- enqueueTaskUsingId :: Double -> ProcessId -> Process a -> Event (Task a)
- taskParallelResult :: Task a -> Task a -> Process (TaskResult a, Task a)
- taskParallelProcess :: Task a -> Task a -> Process (a, Task 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 IOException | the specified exception was raised when performing the task. |
TaskCancelled | the task was cancelled |
taskId :: Task a -> ProcessId Source #
Return an identifier for the process that was launched in background for this task.
tryGetTaskResult :: Task a -> Event (Maybe (TaskResult a)) Source #
Try to get the task result immediately without suspension.
taskResult :: Task a -> Process (TaskResult a) Source #
Return the task result suspending the outer process if required.
taskResultReceived :: Task a -> Signal (TaskResult a) Source #
Return a signal that notifies about receiving the result of the task.
taskProcess :: Task a -> Process 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.
cancelTask :: Task a -> Event () Source #
Cancel the task.
Running Task
runTask :: Process a -> Event (Task a) Source #
Run the process in background and return the corresponding task immediately.
runTaskUsingId :: ProcessId -> Process a -> Event (Task a) Source #
Run the process with the specified identifier in background and return the corresponding task immediately.
Spawning Tasks
spawnTask :: Process a -> Process (Task a) Source #
Run a child process in background and return immediately the corresponding task.
spawnTaskUsingId :: ProcessId -> Process a -> Process (Task a) Source #
Run using the specified identifier a child process in background and return immediately the corresponding task.
spawnTaskWith :: ContCancellation -> Process a -> Process (Task a) Source #
Run a child process in background and return immediately the corresponding task.
spawnTaskUsingIdWith :: ContCancellation -> ProcessId -> Process a -> Process (Task a) Source #
Run using the specified identifier a child process in background and return immediately the corresponding task.
Enqueueing Task
enqueueTask :: Double -> Process a -> Event (Task a) Source #
Enqueue the process that will be started at the specified time from the event queue. It returns the corresponding task immediately.
enqueueTaskUsingId :: Double -> ProcessId -> Process a -> Event (Task 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 :: Task a -> Task a -> Process (TaskResult a, Task a) Source #
Return the result of two parallel tasks.