I usually use task.spawn
to make a new thread, but sometimes coroutine.wrap
. My scripting inconsistent made me realize, what’s the difference between task.spawn
and coroutines?
Coroutines you can stop and start with the script, but task.spawn will just run until all the code has been executed.
There isnt really a difference, but spawn() has a built in wait() into it before the code within it executes. Whereas coroutine executions are instantaneous.
And like @Orbular3 said. You can stop and resume a coroutine. You cannot with spawn()
Any difference performance wise?
spawn()
(or the new task.spawn()
) will fire code immediately.
spawn()
is deprecated, and task.spawn()
should be used to enhance performance
overall, there isn’t a performance difference, coroutines
fire code alongside a thread, task.spawn
does it with the engine sheduler.
Late reply, but is this true? Because you can also stop a new thread of task.spawn with .cancel
edit: Wait no, you can pause a coroutine and continue it later but a task function no
Yes, my solution is wrong.
The task library actually uses coroutines and functions like task.spawn
are just abstractions of the coroutine library.
In other words task and coroutine are the same, except task simplifies the process in exchange for less control - at least that’s what roblox says:
In most cases using a function is sufficient, but for more advanced cases it’s recommended you familiarize yourself with the coroutine library.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.