self:await
Shared
Suspends the thread until the given promise settles, then returns its resolved values
Syntax
local status, ... = self:await(
promise
)This function must be called from within a running thread. It cannot be used outside a thread context, while the thread is sleeping, or while it is already awaiting another util.promise.
- Resolved — resumes the thread with
truefollowed by the resolved values. - Rejected — resumes the thread with
falsefollowed by the rejection values. - Already settled — returns immediately without yielding.
Parameters
| Type | Name | Description |
|---|---|---|
promise | promise | Promise instance to await |
Returns
| Type | Name | Description |
|---|---|---|
status | resolved | true if the promise resolved, false if it was rejected |
any | ... | Values the promise was settled with |
Examples
local promise = util.promise.create()
local entity = util.thread.create(function(self)
local ok, result = self:await(promise)
core.engine.print("info", "Resolved:", ok, result)
end)
entity:resume()
promise:resolve("done")local promise = util.promise.create()
local entity = util.thread.create(function(self)
local ok, value = self:await(promise)
if ok then
core.engine.print("info", "Success:", value)
else
core.engine.print("error", "Failed:", value)
end
end)
entity:resume()
promise:reject("something went wrong")