GreekForge
(GreekForge)
August 26, 2021, 4:28pm
#1
I was wondering since now that task.spawn
is a viable option whether it was still worth using coroutines or not.
The first advantage I can think of with task.spawn
is that it actually has a debug traceback, while a coroutine locks that behind “Error at line 1” .
But, they do accomplish the same thing. What do y’all think?
5 Likes
Did you find out the answer to your question I am also wondering too.
3 Likes
GreekForge
(GreekForge)
September 23, 2021, 5:38pm
#3
No. All I learned was that the advantage of task.spawn
returning a debug traceback wasn’t actually an existing advantage. I was testing with some of my programs, and I had an error inside of a task.spawn
which didn’t print to the console.
1 Like
sleitnick
(sleitnick)
September 23, 2021, 6:23pm
#4
I personally would always prefer task.spawn/defer
over coroutine.wrap
. You can even create your own wrap
function that uses spawn
instead:
local function wrap(fn)
local thread = coroutine.create(fn)
return function()
task.spawn(thread)
end
end
Not sure why you’d want to do that, but you could.
The biggest reason is stack trace, as you mentioned before.
12 Likes
nakata1609
(nakata1609)
October 17, 2021, 10:03am
#5
task.spawn just slightly slower then corontine according to benchmark tests i saw on the new task library post
10 Likes
VoxelDeo
(VoxelDeo)
January 19, 2025, 7:54am
#6
By that you mean that it runs after a shorter time or that it has faster performance?