task.defer

Queues a function on the executor scheduler.

Syntax

Signature
task.defer(Callback: function, ...: any) -> thread

Aliases

  • task.spawn

Parameters

ParameterTypeDescription
CallbackfunctionFunction to run on the executor scheduler.
......anyArguments passed to Callback.

Returns

TypeDescription
threadNew coroutine queued for execution.

Notes

task.spawn and task.defer currently use the same queue. Only functions are accepted. The returned coroutine has not run when this call returns.

Example

Luau
local Job = task.spawn(function(Name)
    print("Started:", Name)
    task.wait(0.5)
    print("Finished:", Name)
end, "Example")

print("Queued coroutine:", Job)
-- task.defer uses the same queue in this executor.