|luk3yx d2ac8715cf Remove stray print().||3 settimane fa|
|LICENSE.md||3 settimane fa|
|README.md||3 settimane fa|
|core.lua||3 settimane fa|
|init.lua||3 settimane fa|
|locks.lua||3 settimane fa|
|lua51.lua||3 settimane fa|
|mod.conf||3 settimane fa|
|test.lua||3 settimane fa|
|transpile.lua||3 settimane fa|
asyncio to not conflict with the similar-but-different async mod.
async function and
async for syntax can only be used with
asyncio.dofile and is run through a
primitive transpiler(?) that converts the syntax into valid lua.
The following functions are available both inside and outside of coroutines:
asyncio.run(function(...)): Executes a function inside an asyncio coroutine.
asyncio.coroutine(function(...)): A function wrapper that runs the function inside a coroutine.
asyncio.exec(...): Similar to
asyncio.dofile work the same
way as their built-in counterparts, however these functions also accept
async function and
async for syntax, and the code itself is executed inside
The following functions only work inside coroutines:
asyncio.await(...): Suspends execution of the current coroutine until
asyncio.resumeis called. If
asyncio.resumeis never called, the coroutine will be garbage collected by lua. Example:
asyncio.resume: This should not be called inside the coroutine itself, instead used as a callback function.
asyncio.resumechanges depending on what coroutine is running, and is
niloutside of coroutines.
asyncio.sleep(delay): Suspends execution of the current coroutine for
delayseconds. Internally, this just calls
asyncio.defer(): Defers execution of this coroutine until the next globalstep.
asyncio.optional_defer(): Allows asyncio to defer, however leaves the decision to actually defer up to asyncio. Currently, it will only call
defer()if it has been over 5ms since the previous “successful”
optional_defer(), however this may change in the future. Returns
asyncio.defer()was actually called, otherwise
asyncio.odefer(): Alias for
asyncio.iter(func, ...): Calls
funcas an asyncio iterator.
asyncio.pairs(obj, defer_every): Similar to
pairs(), but calls
defer_everyiterations. Must be called in an
async forloop or with
asyncio.optional_defer()is called on every iteration instead.
asyncio.ipairs(obj, defer_every): The same as
asyncio.pairs, but with
asyncio.yield(...): Used to yield values in asyncio iterators. This function is slightly different from
coroutine.yieldand should not be used interchangeably with it.
asyncio.running: A variable, set to
truewhen inside a coroutine. Do not manually set this, or it will break.
function(...)in a separate coroutine, so it does not block the current one.
asyncio.domodfile(file): Calls something similar to
asyncio.dofile(current_modpath .. '/' .. file).
asyncio coroutines can be created in one of two ways:
async function sytnax will only work in lua code loaded with
await coroutines from other coroutines, and calling
coroutines from non-asynchronous code will work correctly.
asyncio iterators can only be used inside coroutines.
calculates and stores all iteration values before starting the loop. This
greatly reduces performance, especially when using
async for does not have this limitation, however, and is
therefore recommended over
For another iterator example, see here.
asyncio.await(http.fetch(req, asyncio.resume)), where
http is the name of
HTTPApiTable. This will return the response table.
http.fetch multiple times, it may be easier
to define an asyncio HTTP fetch function:
local function http_fetch(req) return asyncio.await(http.fetch(req, asyncio.resume)) end
wait until <condition> statement, that checks
condition every globalstep until it evaluates to
true, and then continues
executing the thread.
Do not use
wait until unless there is no other way, it can and will create
These are similar to Python’s asyncio locks.