NoRedInk/elm-task-extra/1.0.1

NOTE: this package is not compatible with Elm 0.19.1

Task.Extra

Contains a list of convenient functions that cover common use cases for tasks.

Chaining Tasks

optional : List (Task x value) -> Task y (List value)

Similar to Task.sequence. The difference with Task.sequence is that it doesn't return an error if any individual task fails. If an error is encountered, then this function will march on and perform the next task ignoring the error.

parallel : List (Task error value) -> Task error (List ThreadID)

Analogous to Task.sequence. Schedule a list of tasks to be performed in parallel as opposed to in series as is the case with Task.sequence.

Note that there is no guarantee that the tasks will be performed or complete in the order you have stated. This is why you may use the returned ThreadID for re-ordering or consider integrating a sorting mechanism within your program.

Communicating with Mailboxes

broadcast : List (Address a) -> a -> Task error ()

Sends a value to a list of addresses at once.

Address (Result error value)
-> Task error value
-> Task error value

Intercept the values computed by a task by sending them to appropriate an address. The address accepts a Result such as to capture both successful values and error values. The intercepted task will simply succeed on success with the successful value and fail on failure with the error thus making the interception process feel as though the task is unaffected.

interceptSuccess : Address value -> Task error value -> Task error value

Intercept the successful value computed by a task by sending it to the given address. The result task will just succeed after being sent to the address thus making the interception process feel as though the task is unaffected.

interceptError : Address error -> Task error value -> Task error value

Intercept the error value computed by a task by sending it to the given address. The result task will just fail after being sent to the address thus making the interception process feel as though the task is unaffected.

Make operations async

computeLazyAsync : Address value -> (() -> value) -> Task error ()

Compute a lazy value asynchronously and send the result to an address.

Delay a task

delay : Time -> Task error value -> Task error value

Delay a task by a given amount of time in milliseconds.

Looping forever

loop : Time -> Task error value -> Task error ()

Runs a task repeatedly every given milliseconds.

loop 1000 myTask -- Runs `myTask` every second