Jump to content




How do I Parallel functions inside table?


  • You cannot reply to this topic
3 replies to this topic

#1 CCGrimHaxor

  • Members
  • 140 posts

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.

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

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.

#3 wieselkatze

  • Members
  • 221 posts
  • LocationGermany

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.

#4 CCGrimHaxor

  • Members
  • 140 posts

Posted 07 January 2015 - 08:16 PM

Thanks for the replys It worked





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users