Difference between revisions of "Parallel (API)"
From ComputerCraft Wiki
MKlegoman357 (Talk | contribs) (Added {{NeedsWork}} Tag) |
MKlegoman357 (Talk | contribs) m (Expanded) |
||
Line 2: | Line 2: | ||
Parallel is an API which allows you to multitask. | Parallel is an API which allows you to multitask. | ||
+ | |||
+ | The functions are not actually executed simultaniously, but rather this API will automatically switch between them whenever they yield (eg whenever they call [[coroutine.yield]](), or functions that call that - eg [[os.pullEvent]]() - or functions that call that, etc - basically, anything that causes the function to "pause"). | ||
+ | |||
+ | Each function executed in "parallel" gets its own copy of the event queue, and so "event consuming" functions (again, mostly anything that causes the script to pause - eg [[sleep]](), [[rednet.receive]](), most of the [[Turtle (API)|turtle API]], etc) can safely be used in one without affecting the event queue accessed by the other. | ||
{{API table|Parallel|image=Grid disk.png|2= | {{API table|Parallel|image=Grid disk.png|2= | ||
{{API table/row | {{API table/row | ||
− | |[[parallel.waitForAny]](function1, function2, ...)|{{type| | + | |[[parallel.waitForAny]](function1, function2, ...) |
+ | |{{type|number}} stoppedFunction | ||
|Runs all the functions at the same time, and stops when any of them returns. | |Runs all the functions at the same time, and stops when any of them returns. | ||
|odd}} | |odd}} | ||
{{API table/row | {{API table/row | ||
− | |[[parallel.waitForAll]](function1, function2, ...)|{{type|nil}} | + | |[[parallel.waitForAll]](function1, function2, ...) |
+ | |{{type|nil}} | ||
|Runs all the functions at the same time, and stops when all of them have returned. | |Runs all the functions at the same time, and stops when all of them have returned. | ||
|}} | |}} |
Revision as of 18:15, 10 April 2014
This page needs some serious TLC, stat! Please help us by cleaning it, fixing it up, or sparing it some love.
(Reason: This API needs explanation and examples. MKlegoman357 20:41, 6 April 2014 (GMT)) |
Parallel is an API which allows you to multitask.
The functions are not actually executed simultaniously, but rather this API will automatically switch between them whenever they yield (eg whenever they call coroutine.yield(), or functions that call that - eg os.pullEvent() - or functions that call that, etc - basically, anything that causes the function to "pause").
Each function executed in "parallel" gets its own copy of the event queue, and so "event consuming" functions (again, mostly anything that causes the script to pause - eg sleep(), rednet.receive(), most of the turtle API, etc) can safely be used in one without affecting the event queue accessed by the other.
Parallel (API) | ||
---|---|---|
Function | Return values | Description |
parallel.waitForAny(function1, function2, ...) | number stoppedFunction | Runs all the functions at the same time, and stops when any of them returns. |
parallel.waitForAll(function1, function2, ...) | nil | Runs all the functions at the same time, and stops when all of them have returned. |