Parallel.waitForAny
From ComputerCraft Wiki
Revision as of 21:54, 27 January 2016 by Dan200 (Talk | contribs) (Removed very misleading incorrect note)
| Lets you run multiple functions at the same time, alternating between them until any happen to finish. | |
| Syntax | parallel.waitForAny(function function1, function function2, ...) |
| Returns | number indicating which function has completed based on argument order |
| Part of | ComputerCraft |
| API | parallel |
Examples
| 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. |