Questions around spawn(function)

So maybe a few days ago, or a week, they released the Task Library, which made wait(), spawn(), and something else deprecated. Replacing it with the new methods of task.wait(), and task.spawn(). Wait is particularly useful, but I still haven’t learned much about spawn. I know it starts function, and uses a “new thread”, but what does that mean in plain english. I understand most of the API, studio, and computer stuff. I assume it uses the players computer, but unsure. If someone could explain. That’d be greatly appreciated.

Atm, I’m aware it’s not as efficient as most methods.

The spawn() function would have a built-in wait() in it, and then run the code on a new thread, very similarly to a coroutine. The new task.spawn() uses the fast spawn method (if I recall correctly), which uses event-based code to run as quickly as possible.

Hope this cleared things up.

1 Like

So by thread, it’s essentially a coroutine, that makes a bit more sense. (aka different part in the script) How long is the wait? Is it just a wait()?

It was just a wait() with no parameter. The time varies, but it was something like 0.03 seconds or something.

Also to add to your discussion of a thread:
A thread is basically a piece of code. Coroutines, spawning, etc, allows for multiple threads to run alongside one another, allowing for two (or more) pieces of code running at the same time.

just to let you know
task.spawn() is based on the fastSpawn pattern
while task.defer() is more of a replacement for spawn()

1 Like

Yeah, wait() defaults to 0.03 seconds. It’s as low as it goes. task.wait goes one decimal spot lower, which is nicer. I wonder if the wait() in spawn was replaced with task.wait(). I assume so.

well wait() is deprecated so they should be using something else

Spawn and wait are both deprecated at this point, which I assume means the original spawn() function is unaltered. I recommend task.spawn() over spawn().

1 Like