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 (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ᵢ))
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)]
fun diffused(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 not preserved.list(diffused(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) * (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
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.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 ifQueue
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 task::queue(MaxRunning: integer, Callback: function): 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.