Concerns about using spawn(function()

So, I have just heard about why coroutines > spawn and blah blah, not LOOKING to start another spawn vs coroutines debate here (which will PROBABLY happen regardless). I use spawn(function() for simple stuff like disabling stuff, or cooldowns. They are pretty minor stuff but I use ALOT of them and I was wondering if I should either switch to coroutines or just not use them entirely?

Yeah you can switch to explicit coroutines, but a disadvantage is that it kills the stack trace upon an exception. I’ve seen an implementation of a “fast spawn” using bindable events, which mitigates the 1/30 delay when using spawn. It worked something like this.

-- This is just how I would do it.
local function fast_spawn(fn, ...)
    local bindable = Instance.new("BindableEvent")
    local connection = bindable.Event:Connect(fn)
    bindable:Fire(...)
    connection:Disconnect()
end
4 Likes

oh that’s actually a really smart way of going about it

This exact point was raised on that Coroutine vs Spawn thread. If you have an abundance of spawns, use a different implementation that involves either BindableEvents or coroutines. Spawn has no guarantees that your threads will start up in the time you expect, much less if they will at all.

For the matter of coroutines supposedly killing stack traces:

4 Likes

@colbert2677 pretty much answered this, but this video helped me understand the advantages of using coroutines versus spawn() & delay().

2 Likes

Yikes… just watched the video. Damn