task
Per-frame coroutine scheduler in wall-clock seconds; tasks die with their script.
Functions
task.spawn
task.spawn(fn)| Name | Type | Description |
|---|---|---|
| fn | function | Coroutine body, no arguments. |
Runs fn as a task, starting next frame.
An error is logged and ends only that task.
task.defer
task.defer(fn)| Name | Type |
|---|---|
| fn | function |
Same as task.spawn.
task.wait
task.wait([seconds = 0])| Name | Type | Description |
|---|---|---|
| secondsoptional | number | 0 or less: next frame. Default 0. |
Suspends the current task for at least seconds.
Raises outside task.spawn, defer, delay or interval.
task.delay
task.delay(seconds, fn) -> cancel| Name | Type | Description |
|---|---|---|
| seconds | number | |
| fn | function | Called once. |
Runs fn once after a delay.
Returns cancel function
task.interval
task.interval(seconds, fn) -> cancel| Name | Type | Description |
|---|---|---|
| seconds | number | 0 calls fn every frame. |
| fn | function |
Calls fn every interval, first after one interval.
Returns cancel function
- Timed from each call's end, so a slow fn drifts.
- An error in fn ends the timer.