Hello, i'm trying to find the difference between a spawn() thread and a coroutine, are these two basicly the same thing when starting?
Hi Lunatic,
Thanks,
Best regards,
~~ KingLoneCat
There is actually a slight difference in the performance of each event.
coroutines are less likely to stop under normal circumstances. For example if the script hosting the routine is disabled, it's likely the coroutine will keep running. Also once the coroutine is called it runs immediately.
In contrast, spawn is definitely better because it ends when it logically should and you don't need to keep that close of an eye on it. Downside is rather than running immediately when called, spawn() will make a new task that won't be run in the task scheduler until a script calls the wait service by using wait() so something like this would run instantly:
spawn(function() end) wait()
A better method than either of those is simply delay, this works exactly the same as spawn but with no need of the wait service(if you're not the kind of person who uses wait()). You can simply call:
delay(0,function() end)
and that would run instantly in a single block. You could also set delay times which is a good plus.