I have this module script with a bunch of coroutines in it for this lets say npc system controlling multiple objects in one script.
This grand loop doesn’t go forever. A stop and go sort of system. Turning loops off when they are not needed type of thing. The only thing I can’t turn off is the coroutines. I can halt all functions and actions in them but I read even then the coroutine is still taking up memory? Even though in theory it’s dead. In application it’s really dead? And not doing anything?
All my options require turning my functions into threads. I do not want to turn everything into task functions as the system just won’t work as smoothly I fear.
I read this and tried it and I just don’t know if it’s actually stopping anything.
My question is what is this thread generated exactly and does it have any tie to the coroutines in my module? I adapted this method into my function that turns everything off. I see no difference in how it is performing. Also the threads are always random, never the same thread? Are the threads even being canceled whether or not they are connected to my coroutines?
I also want to add, if I remove task,defer the thread cannot be canceled. Based on reading what defer does this in theory is perfect. At the end of the coroutine cycle do something…(task.cancel, thread) but is it actually canceling the thread. What is this mysterious thread that is never the same? Is it a chain reaction. I assume threads are randomly generated in terms of the ID but it’s actually the same thing(x). My mind is confused.
EDIT****
I just did a test with task.spawn(func) and the output says cannot resume dead coroutine. So I’m so confused. I have no code manually closing the coroutines but the engine says it’s dead…IS IT?