Garry's Mod Wiki

Garry's Mod Wiki

Coroutines are similar to threads, however they do not run simultaneously. They offer a way to split up tasks and dynamically pause & resume functions.

Methods

thread coroutine.create( function func )
Creates a coroutine of the given function.
boolean coroutine.isyieldable()
Returns whether the running coroutine can yield. A running coroutine is yieldable if it is not in the main thread, and it is not inside a non-yieldable C function. This is only available on the x86-64 versions, because of the difference in the LuaJIT version. See here
boolean, vararg coroutine.resume( thread coroutine, vararg args )
Resumes the given coroutine and passes the given vararg to either the function arguments or the coroutine. yield that is inside that function and returns whatever yield is called with the next time or by the final return in the function.
thread coroutine.running()
Returns the active coroutine or nil if we are not within a coroutine.
string coroutine.status( thread coroutine )
Returns the status of the coroutine passed to it, the possible statuses are "suspended", "running", and "dead".
coroutine.wait( number duration )
Repeatedly yields the coroutine for the given duration before continuing. Only works inside a coroutine. Only useful in nextbot coroutine think function. This function uses CurTime instead of RealTime.
function coroutine.wrap( function coroutine )
Returns a function which calling is equivalent with calling coroutine. resume with the coroutine and all extra parameters. The values returned by the returned function only contain the values passed to the inner coroutine. yield call and do not include the no error status that coroutine. resume provides. In case of failure, an error is thrown instead.
vararg coroutine.yield( vararg returnValue )
Pauses the active coroutine and passes all additional variables to the call of coroutine. resume that resumed the coroutine last time, and returns all additional variables that were passed to the previous call of resume.

This site is a community mirror of the official Garry's Mod wiki.. This site is not maintained by Facepunch Studios.

Page content is automatically updated twice a day. Edits and history are not available.

Last Parsed: Loading...