Skip to content

coroutinelib

close

function coroutine.close(co: thread)
  -> noerror: boolean
  2. errorobject: any

Closes coroutine co , closing all its pending to-be-closed variables and putting the coroutine in a dead state.

View documents

create

function coroutine.create(f: fun(...any):...unknown)
  -> thread

Creates a new coroutine, with body f. f must be a function. Returns this new coroutine, an object with type "thread".

View documents

isyieldable

function coroutine.isyieldable(co?: thread)
  -> boolean

Returns true when the coroutine co can yield. The default for co is the running coroutine.

View documents

resume

function coroutine.resume(co: thread, val1?: any, ...any)
  -> success: boolean
  2. ...any

Starts or continues the execution of coroutine co.

View documents

running

function coroutine.running()
  -> running: thread
  2. ismain: boolean

Returns the running coroutine plus a boolean, true when the running coroutine is the main one.

View documents

status

function coroutine.status(co: thread)
  -> "dead"|"normal"|"running"|"suspended"

Returns the status of coroutine co.

View documents

return #1:
    | "running" -- Is running.
    | "suspended" -- Is suspended or not started.
    | "normal" -- Is active but not running.
    | "dead" -- Has finished or stopped with an error.

wrap

function coroutine.wrap(f: fun(...any):...unknown)
  -> fun(...any):...unknown

Creates a new coroutine, with body f; f must be a function. Returns a function that resumes the coroutine each time it is called.

View documents

yield

(async) function coroutine.yield(...any)
  -> ...any

Suspends the execution of the calling coroutine.

View documents