Thread
The Thread module allows an alternative to the built-in globals spawn
and delay
. The built-in globals are known to throttle unexpectedly. The Thread module will provide the expected behavior for spawning and delayed spawning of new threads.
Please note that the Lua runtime is single-threaded, and any multi-threading applications are simply utilizing the underlying task scheduler to appear multi-threaded.
Thread.SpawnNow(Function func [, Variant args...])
¶
Spawns the given function on a new thread immediately. Internally, this is done by creating, firing, and destroying a BindableEvent. Due to this process, SpawnNow
is not necessarily a well-performing operation, and thus should not be used when performance needs to be optimal.
1 2 3 |
|
Thread.Spawn(Function func, [, Variant args...])
¶
Spawns the given function on a new thread. Internally, this is done using RunService's Heartbeat event, which means that the function will be spawned on the next heartbeat step (i.e. next frame).
1 2 3 |
|
Thread.Delay(Number waitTime, Function func [, Variant args...])
¶
Spawns the given function on a new thread after waitTime
has elapsed. Internally, this is the same as the above Thread.Spawn
function, except for the delayed start.
Because this function returns the heartbeat connection, the delay can be cancelled by disconnecting the connection.
Returns: Connection
1 2 3 4 5 6 7 8 9 10 11 |
|
Thread.DelayRepeat(Number tm, Function func [, Variant args...])
¶
Continuously calls func
after tm
seconds on a new thread.
1 2 3 4 5 6 |
|