tasks¶
fun parallel(Sequence: any, Max?: integer, Min?: integer, Fn: function): nil | error
Iterates through
Sequence
and callsFn(Key, Value)
for eachKey, Value
pair produced without waiting for the call to return. The call toparallel
returns when all calls toFn
return, or an error occurs. IfMax
is given, at mostMax
calls toFn
will run at a time by pausing iteration throughSequence
. IfMin
is also given then iteration will be resumed only when the number of calls toFn
drops toMin
.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 callsMain(Tasks)
. The call totasks(...)
returns whenMain
and all tasks created withinMain
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 mostMaxRunning
child tasks in parallel, and callsMain(Tasks)
. The call totasks(...)
returns whenMain
and all tasks created withinMain
complete.meth tasks(MaxRunning: integer, MaxPending: integer, Main: function): nil | error
Creates a new
tasks
set which will run at mostMaxRunning
child tasks in parallel, and callsMain(Tasks)
. The call totasks(...)
returns whenMain
and all tasks created withinMain
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ᵢ))
whereKᵢ, Vᵢ
are the keys and values produced bySequence
. The calls toFn
are done in parallel, with at mostSize
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()
orTask: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
withResult
, resuming any waiting code. Raises an error ifTask
is already complete.meth (Task: task):error(Type: string, Message: string): any | error
Completes
Task
with anerror(Type, Message)
, resuming any waiting code. Raises an error ifTask
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 runsFn(Arg₁, ..., Argₙ)
.