Difference between revisions of "Parallel.waitForAll"
From ComputerCraft Wiki
m (Moved to CAT:APIFunctions) |
MKlegoman357 (Talk | contribs) m (Fixed) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Function | {{Function | ||
|name=parallel.waitForAll | |name=parallel.waitForAll | ||
− | |args= function1, function2, | + | |args= {{type|function}} function1, {{type|function}} function2, ... |
− | |returns = | + | |returns=None |
|api=parallel | |api=parallel | ||
|addon=ComputerCraft | |addon=ComputerCraft | ||
− | |desc=Lets you run multiple functions at the same time. | + | |desc=Lets you run multiple functions at the same time, alternating between them until all have finished. Note that it takes ''function names'' as parameters (eg "function1", "function2", etc), as opposed to ''function calls'' (eg "function1()", "function2()", etc). |
|examples= | |examples= | ||
{{Example | {{Example | ||
− | |desc=Tells the computer to run function1 and function2 at the same time. Will broadcast what the | + | |desc=Tells the computer to run function1 and function2 at the same time. Will broadcast what the user enters and prints what it receives over rednet. It will stop when it has received a message ''and'' the user has entered something. |
− | |code= | + | |code=local function receive () -- Define the first function. |
− | [[print]] ([[rednet.receive]]()) | + | [[print]]([[rednet.receive]]()) |
end | end | ||
− | + | ||
− | [[rednet.broadcast]] ([[read]]()) | + | local function send () -- Define the second function. |
+ | [[rednet.broadcast]]([[read]]()) | ||
end | end | ||
− | parallel.waitForAll ( | + | |
+ | '''parallel.waitForAll(receive, send)''' -- Run both functions in parallel and wait until both of them completes. | ||
|output=Prints what it received via rednet and broadcasts the message the user typed. | |output=Prints what it received via rednet and broadcasts the message the user typed. | ||
}} | }} |
Latest revision as of 18:10, 10 April 2014
Function parallel.waitForAll | |
Lets you run multiple functions at the same time, alternating between them until all have finished. Note that it takes function names as parameters (eg "function1", "function2", etc), as opposed to function calls (eg "function1()", "function2()", etc). | |
Syntax | parallel.waitForAll(function function1, function function2, ...) |
Returns | None |
Part of | ComputerCraft |
API | parallel |
Examples
Example | |
Tells the computer to run function1 and function2 at the same time. Will broadcast what the user enters and prints what it receives over rednet. It will stop when it has received a message and the user has entered something. | |
Code |
local function receive () -- Define the first function. print(rednet.receive()) end local function send () -- Define the second function. rednet.broadcast(read()) end parallel.waitForAll(receive, send) -- Run both functions in parallel and wait until both of them completes. |
Output | Prints what it received via rednet and broadcasts the message the user typed. |