Library

task

globalstable

Task scheduling and yielding. Provides Roblox-shape wait, spawn, defer, delay on top of the VM's coroutine scheduler. Exposed both at the task table and as globals.

Functions

5

#task.delay(duration: number, callback: function, ...args: ...any) → thread

since 0.6.0-dev

Schedules callback to run after at least duration seconds. Extra arguments are forwarded to the callback.

Parameters

durationnumber

Delay in seconds.

callbackfunction

Function to call.

...args...any

Arguments forwarded to the callback.

#task.spawn(callback: function, ...args: ...any) → thread

since 0.6.0-dev

Calls callback immediately in a new thread with the given arguments.

Parameters

callbackfunction

Function to call.

...args...any

Arguments forwarded to the callback.

Errors

  • LuaError internal error -- VM engine context unavailable.

#task.defer(callback: function, ...args: ...any) → thread

since 0.6.0-dev

Schedules callback to run at the end of the current resumption cycle. Extra arguments are forwarded to the callback.

Parameters

callbackfunction

Function to call.

...args...any

Arguments forwarded to the callback.

#task.wait(duration: number?) → number

yieldssince 0.6.0-dev

Yields the calling thread for at least duration seconds. Returns the actual elapsed time.

Parameters

durationnumber?

Duration in seconds (default 0).

Errors

  • LuaError internal error -- VM engine context unavailable.

#task.cancel(thread: thread) → boolean, string?

since 1.6.11-alpha

Cancels a thread and resets it so it can no longer be resumed. The thread must be suspended, finished, or errored, and a thread cannot cancel itself. Returns true if it was cleanly cancelled, or false plus the thread's error message if it had already failed.

Aliasesclose

Parameters

threadthread

The thread to cancel.

Errors

  • LuaError cannot cancel -- Target thread cannot be cancelled in its current state.