coroutine.wrap
creates a new coroutine based on the function you passed it, and then creates a new function based on the coroutine. The first time you call it, it calls the original function until it yields. The next time, it returns from the yield and runs until the next yield. And so on.
In ComputerCraft, yielding is the same as waiting for an event.
ComputerCraft comes with the parallel
library which runs two or more functions as coroutines in parallel. It does all the work for you.
You can use parallel.waitForAll
or parallel.waitForAny
, depending on when you want it to return.
Usage: parallel.waitForAll(constantWork, lookForKeys)