tasks

fun parallel(Sequence: any, Max?: integer, Min?: integer, Fn: function): nil | error

Iterates through Sequence and calls Fn(Key, Value) for each Key, Value pair produced without waiting for the call to return. The call to parallel returns when all calls to Fn return, or an error occurs. If Max is given, at most Max calls to Fn will run at a time by pausing iteration through Sequence. If Min is also given then iteration will be resumed only when the number of calls to Fn drops to Min.

meth (Fn: function):else(Else: function): task

TBD

meth (Fn: function):on(On: function): task

TBD

meth (Fn: function):then(Then: function): task

Equivalent to task(Fn, call -> Then).

meth (Fn: function):then(Then: function, Else: function): task

TBD

fun buffered(Sequence: sequence, Size: integer, Fn: function): sequence

Returns the sequence (Kᵢ, Fn(Kᵢ, Vᵢ)) where Kᵢ, Vᵢ are the keys and values produced by Sequence. The calls to Fn are done in parallel, with at most Size calls at a time. The original sequence order is preserved (using an internal buffer).

list(buffered(1 .. 10, 5, tuple))
:> [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10)]
type task < function

A task representing a value that will eventually be completed.

meth task(): task

Returns a task. The task should eventually be completed with Task:done() or Task:error().

meth task(Arg₁: any, ..., Argₙ: any, Fn: function): task

Returns a task which calls Fn(Arg₁, ..., Argₙ).

meth (Task₁: task) * (Task₂: task): task::set

Returns a task::set that completes when all of its sub tasks complete, or any raises an error.

meth (Task₁: task) + (Task₂: task): task::set

Returns a task::set that completes when any of its sub tasks complete, or any raises an error.

meth (Task: task):done(Result: any): any | error

Completes Task with Result, resuming any waiting code. Raises an error if Task is already complete.

meth (Task: task):error(Type: string, Message: string): any | error

Completes Task with an error(Type, Message), resuming any waiting code. Raises an error if Task is already complete.

meth (Task: task):wait: any | error

Waits until Task is completed and returns its result.

meth (Tasks: task::list):wait: any | error

Waits until all the tasks in Tasks are completed or any task returns an error.

type task::queue < function

A queue of tasks that can run a limited number of tasks at once.

fun (Queue: task::queue)(Arg₁, ..., Argₙ, Fn): task

Returns a new task that calls Fn(Arg₁, ..., Argₙ). The task will be delayed if Queue has reached its limit.

meth task::queue(MaxRunning: integer): task::queue

Returns a new task queue which runs at most MaxRunning tasks at a time.

meth (Arg₁: task::queue):cancel

TBD

type task::set < task

A task combining a set of sub tasks.