Should I use corutine.wrap() or task.spawn()?

I am currently making framework for my game. I just want to know, when I am listening to an event, should I use corutine.wrap() or task.spawn() to run it in a different thread.

Thanks in advance!

Do you need the return value(s)? If so use coroutine.wrap, otherwise it’s essentially down to preference.

local function f()
	return "Hello world!"
end

local t = coroutine.wrap(f)
local r = t()
print(r) --Hello world!
2 Likes