Parallel.waitForAny

From ComputerCraft Wiki
Jump to: navigation, search
Grid Redstone.png  Function parallel.waitForAny
Lets you run multiple functions at the same time, alternating between them until any happen to finish. Note that it takes function names as parameters (eg "function1", "function2", etc), as opposed to function calls (eg "function1()", "function2()", etc).
Syntax parallel.waitForAny(function function1, function function2, ...)
Returns number indicating which function has completed based on argument order
Part of ComputerCraft
API parallel

Examples

Grid paper.png  Example
Tells the computer to run receiveand send the same time. Will broadcast what the user enters or prints what it receives over rednet, depending on what happens first.
Code
local function receive ()  -- Define function1.
 print(rednet.receive())
end

local function send ()  -- Define function2.
 rednet.broadcast(read())
end

parallel.waitForAny(receive, send)  -- Run both functions in parallel until one finishes.
Output Either it prints what it received via rednet, or it broadcasts the message the user typed.
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox