Difference between revisions of "Parallel.waitForAny"
From ComputerCraft Wiki
m (Moved to CAT:APIFunctions) |
m (Function -> Function (type)) |
||
Line 9: | Line 9: | ||
{{Example | {{Example | ||
|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. Both will stop when either something is printed or the user entered something. | |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. Both will stop when either something is printed or the user entered something. | ||
− | |code=function1 = [[function]]() | + | |code=function1 = [[Function (type)|function]]() |
[[print]] ([[rednet.receive]]()) | [[print]] ([[rednet.receive]]()) | ||
end | end | ||
− | function2 = [[function]]() | + | function2 = [[Function (type)|function]]() |
[[rednet.broadcast]] ([[read]]()) | [[rednet.broadcast]] ([[read]]()) | ||
end | end |
Revision as of 18:49, 30 November 2012
Function parallel.waitForAny | |
Lets you run multiple functions at the same time. | |
Syntax | parallel.waitForAny(function1, function2, so on) |
Returns | A number indicating which function completed based on argument order |
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. Both will stop when either something is printed or the user entered something. | |
Code |
function1 = function() print (rednet.receive()) end function2 = function() rednet.broadcast (read()) end parallel.waitForAny (function1, function2) |
Output | Either it prints what it received via rednet, or it broadcasts the message the user typed. |