self:sleep
Shared
Suspends the thread for the specified duration, then resumes automatically
Syntax
local status = self:sleep(
duration
)This function must be called from within a running thread. It cannot be used outside a thread context, while already sleeping, or while awaiting a util.promise.
- Available — the thread yields for the given duration and resumes automatically when the timer expires.
- Outside a thread — the call is a no-op and returns
false. - Sleeping or awaiting — the call is ignored and returns
false.
Parameters
| Type | Name | Description |
|---|---|---|
int | duration | Sleep duration in milliseconds, must be >= 0 |
Returns
| Type | Name | Description |
|---|---|---|
bool | status | true on successful execution, false otherwise |
Examples
local entity = util.thread.create(function(self)
core.engine.print("info", "Sleeping for 5 seconds")
self:sleep(5000)
core.engine.print("info", "Awake now")
end)
entity:resume()local entity = util.thread.create(function(self)
for i = 1, 3 do
core.engine.print("info", "Tick", i)
self:sleep(1000)
end
end)
entity:resume()