This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Mackan90096's profile picture

[Question] Coroutines ?

Started by Mackan90096, 06 May 2013 - 03:17 AM
Mackan90096 #1
Posted 06 May 2013 - 05:17 AM
Hi there! I've seen many topics and stuff using coroutines.

What are they? Can someone please explain in detail..

Thanks.
//Mackan90096
1lann #2
Posted 06 May 2013 - 05:27 AM
http://lua-users.org/wiki/CoroutinesTutorial
Generally you would want to stick with parallel.waitForAny or parallel.waitForAll. There are plenty of tutorials on this in the tutorials section. I would link you to some but I'm on my phone at the moment and it's quite a hassle.
theoriginalbit #3
Posted 06 May 2013 - 05:40 AM
As 1lann stated most times you will just want to stick with the parallel api as it is managed coroutines, you don't need to know how they work, you just request them to work.

Also just a slight change to the opening line of that link 1lann posted, coroutines actually cannot allow us to do multiple things at the same time, it may seem to the user that it is at the same time, but actually only one coroutine is running at any given time, and it must yield in order for the next to run… in CC that is where os.pullEvent's come in, they call coroutine.yield.
SuicidalSTDz #4
Posted 06 May 2013 - 07:28 AM
Cranium asked about coroutines. Go check out that post, they are thoroughly explained there.
PixelToast #5
Posted 06 May 2013 - 02:27 PM
coroutines are a bit advanced, if you want basic multitasking use the parallel API:
http://www.computerc...l-parallel-api/