Parallel.waitForAll

From ComputerCraft Wiki
Jump to: navigation, search
Grid Redstone.png  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

Grid paper.png  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.