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

How do I Parallel functions inside table?

Started by CCGrimHaxor, 07 January 2015 - 06:11 PM
CCGrimHaxor #1
Posted 07 January 2015 - 07:11 PM
The title says it all. I want to make a table of functions that will be paralleled. Please help.
KingofGamesYami #2
Posted 07 January 2015 - 07:15 PM
You could unpack() the table into the parallel call, other than that you can write your own parallel script using coroutines.

parallel source code.
wieselkatze #3
Posted 07 January 2015 - 07:20 PM
You could either go the 'manual' way of doing it with coroutines, but you could also use parallel - if that fits your needs.
For example:


local functions = {
    function()
	    for i = 1, 5 do
		    print( "hello" )
		    sleep( 0 )
	    end
    end;

    function()
	    for i = 1, 5 do
		    print( i )
		    sleep( 0 )
	    end
    end;
}

parallel.waitForAll( unpack( functions ) )

The sleep( 0 ) is just there to let parallel switch between the functions, as it has to wait for one function to yield before the other one can be executed.
CCGrimHaxor #4
Posted 07 January 2015 - 08:16 PM
Thanks for the replys It worked