I'm making a driver to a game.
local function Driver() --do stuff end
It needs to be able to escape the sequence at any time. Nomally this is done by checking a variable in a loop, but the driver I have create is much too complex for this repetitive checking.
Coroutines can suspend themselves at any given time. Knowing this, I made the driver into a coroutine that will suspend itself.
local function Driver(co) --do stuff --Some very long stack later coroutine.yield(co); --more stuff end Driver = coroutine.wrap(Driver) Driver(Driver); --Start the driver
So, essentially this driver will be able to escape at any time it wants. Even though the thread is "suspended" and not "dead", it can be garbage collected later since it will be unreferenced.
Is this an acceptable practice? or is there a flaw with it's implementation?