Function
isAsync
Checks whether the code is running inside an async task, i.e. whether it can wait with await or sleep without blocking.
Syntax
bool isAsync()Returns
true inside an async task.
Example
local function saveAll()
if not isAsync() then return async(saveAll) end
sleep(100)
print("zapisano")
end
saveAll()
See also
asyncRuns a function as a task (coroutine). The code in the task runs immediately until its first wait (sleep,await,waitForEvent). Then it yields and the server and the game keep running. When the wait is over, the task continues from where it stopped. This lets you write steps spread over time (a countdown, a database query, an HTTP response, waiting for a player) one after another, without nested callbacks and timers.awaitWaits for a result inside anasynctask. It takes two forms. The first is a starter function: it receivesresumeand starts something that ends in a callback (adbQueryquery,fetchRemote, a timer). When the callback callsresume(...),awaitreturns the same values. The second form is another task fromasync:awaitwaits until it ends and returns its results, and if that task failed, it re-throws the error (catch it withpcall).sleepPauses anasynctask for the given time. Meanwhile other scripts, the server and the game run normally.sleep(0)waits until the next server frame (the same assetTimerwith interval 0).