Difference between revisions of "Parallel.waitForAny"
From ComputerCraft Wiki
MKlegoman357 (Talk | contribs) m (Fixed) |
(Removed very misleading incorrect note) |
||
| Line 5: | Line 5: | ||
|api=parallel | |api=parallel | ||
|addon=ComputerCraft | |addon=ComputerCraft | ||
| − | |desc=Lets you run multiple functions at the same time, alternating between them until any happen to finish | + | |desc=Lets you run multiple functions at the same time, alternating between them until any happen to finish. |
|examples= | |examples= | ||
{{Example | {{Example | ||
Latest revision as of 21:54, 27 January 2016
| 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. |