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 tasks(Main: function): nil | error

Creates a new tasks set with no limits, and calls Main(Tasks). The call to tasks(...) returns when Main and all tasks created within Main complete.

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

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

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

TBD

meth tasks(MaxRunning: integer, Main: function): nil | error

Creates a new tasks set which will run at most MaxRunning child tasks in parallel, and calls Main(Tasks). The call to tasks(...) returns when Main and all tasks created within Main complete.

meth tasks(MaxRunning: integer, MaxPending: integer, Main: function): nil | error

Creates a new tasks set which will run at most MaxRunning child tasks in parallel, and calls Main(Tasks). The call to tasks(...) returns when Main and all tasks created within Main complete.

At most MaxPending child tasks will be queued. Calls to add child tasks will wait until there some tasks are cleared.

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):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.

type tasks < function

A dynamic set of tasks (function calls). Multiple tasks can run in parallel (depending on the availability of a scheduler and/or asynchronous function calls).

fun (Tasks: tasks)(Arg₁, ..., Argₙ, Fn): task

Creates a new task that runs Fn(Arg₁, ..., Argₙ).