Skip to content

task ​

luau
local task = require("@std/task")

WARNING

These APIs are still open to future evolution. In new major versions, they may change in backwards incompatible ways.

Summary ​

EntryDescription
cancelCancels thread, preventing it from being resumed again.
deferSchedules routine to run after the current thread yields, passing any additional arguments to it. Returns the thread.
delaySchedules routine to run after dur seconds, passing any additional arguments to it. Returns the thread.
spawnSchedules routine to run immediately on the next resumption cycle, passing any additional arguments to it. Returns the thread.
waitYields the current thread for dur seconds (or until the next cycle if dur is omitted). Returns the actual time waited.

Functions and Properties ​

task.cancel ​

Cancels thread, preventing it from being resumed again.

luau
(thread: thread) -> ()

task.defer ​

Schedules routine to run after the current thread yields, passing any additional arguments to it. Returns the thread.

luau
(routine: ((T...) -> U...) | thread, ...: T...) -> thread

task.delay ​

Schedules routine to run after dur seconds, passing any additional arguments to it. Returns the thread.

luau
(dur: number, routine: ((T...) -> U...) | thread, ...: T...) -> thread

task.spawn ​

Schedules routine to run immediately on the next resumption cycle, passing any additional arguments to it. Returns the thread.

luau
(routine: ((T...) -> U...) | thread, ...: T...) -> thread

task.wait ​

Yields the current thread for dur seconds (or until the next cycle if dur is omitted). Returns the actual time waited.

luau
(dur: number?) -> number