The parallel api allows you to run many functions at once. It checks for any functions listed in the line of code. It also allows sequencing.
Syntax
parallel.waitForAny(func1, func2, etc.)
parallel.waitForAll(func1, func2, etc.)
How these work
As you can see, waitForAny would wait for any to queue.
waitForAll is for sequencing, it waits for everything to complete.
Why is it helpful?
It helps because it doesn't require lots of lines of code to run 2 functions at one time. It was specifically made for multitasking.
How to use it properly
Say you have a function that you want it to receive all incoming messages.
function recv()
while true do
id, msg = rednet.receive()
print(msg)
end
end
Now you have another function that sends rednet.
function send()
while true do
write("> ")
input = read()
rednet.broadcast(input)
end
end
Now if you are lazy like 75% of all Americans (such obesity, it disgusts me.) You won't want to make a bunch of lines of code making it recv and send at the same time. This is what parallel prevents.
while true do
parallel.waitForAny(recv, send)
end
It simply runs the functions simultaneously!