tasks¶
fun parallel(Sequence: any, Max?: integer, Min?: integer, Fn: function): nil | errorIterates through
Sequenceand callsFn(Key, Value)for eachKey, Valuepair produced without waiting for the call to return. The call toparallelreturns when all calls toFnreturn, or an error occurs. IfMaxis given, at mostMaxcalls toFnwill run at a time by pausing iteration throughSequence. IfMinis also given then iteration will be resumed only when the number of calls toFndrops toMin.meth (Fn: function):else(Else: function): taskTBD
meth (Fn: function):on(On: function): taskTBD
meth (Fn: function):then(Then: function): taskEquivalent to
task(Fn, call -> Then).meth (Fn: function):then(Then: function, Else: function): taskTBD
fun buffered(Sequence: sequence, Size: integer, Fn: function): sequenceReturns the sequence
(Kᵢ, Fn(Kᵢ, Vᵢ))whereKᵢ, Vᵢare the keys and values produced bySequence. The calls toFnare done in parallel, with at mostSizecalls 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): sequenceReturns the sequence
(Kᵢ, Fn(Kᵢ, Vᵢ))whereKᵢ, Vᵢare the keys and values produced bySequence. The calls toFnare done in parallel, with at mostSizecalls 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 < functionA task representing a value that will eventually be completed.
meth task(): taskReturns a task. The task should eventually be completed with
Task:done()orTask:error().meth task(Arg₁: any, ..., Argₙ: any, Fn: function): taskReturns a task which calls
Fn(Arg₁, ..., Argₙ).meth (Task₁: task) * (Task₂: task): task::setReturns a
task::setthat completes when all of its sub tasks complete, or any raises an error.meth (Task₁: task) + (Task₂: task): task::setReturns a
task::setthat completes when any of its sub tasks complete, or any raises an error.meth (Task: task):done(Result: any): any | errorCompletes
TaskwithResult, resuming any waiting code. Raises an error ifTaskis already complete.meth (Task: task):error(Type: string, Message: string): any | errorCompletes
Taskwith anerror(Type, Message), resuming any waiting code. Raises an error ifTaskis already complete.meth (Task: task):wait: any | errorWaits until
Taskis completed and returns its result.meth (Task: task):wait(Arg₂: real): any | errorWaits until
Taskis completed and returns its result.meth (Tasks: task::list):wait: any | errorWaits until all the tasks in
Tasksare completed or any task returns an error.type task::queue < functionA queue of tasks that can run a limited number of tasks at once.
fun (Queue: task::queue)(Arg₁, ..., Argₙ, Fn): taskReturns a new task that calls
Fn(Arg₁, ..., Argₙ). The task will be delayed ifQueuehas reached its limit.
meth task::queue(MaxRunning: integer): task::queueReturns a new task queue which runs at most
MaxRunningtasks at a time.meth task::queue(MaxRunning: integer, Callback: function): task::queueReturns a new task queue which runs at most
MaxRunningtasks at a time.meth (Arg₁: task::queue):cancelTBD
type task::set < taskA task combining a set of sub tasks.