self:reject
Shared
Rejects the promise with the given reason, resuming any threads awaiting it with a failure
Syntax
local status = self:reject(
...
)A promise can only be settled once. Calling self:reject or self:resolve on an already-settled promise has no effect and returns false.
- Pending — the promise is rejected and all awaiting threads are resumed with the provided rejection values.
- Already settled — the call is ignored and
falseis returned.
Parameters
| Type | Name | Description |
|---|---|---|
any | ... | One or more values describing the rejection reason |
Returns
| Type | Name | Description |
|---|---|---|
bool | status | true if the promise was successfully rejected, false if it was already settled |
Examples
local entity = util.promise.create()
entity:reject("something went wrong")local entity = util.promise.create()
entity:reject("connection timed out")
util.thread.create(function(self)
local ok, err = self:await(entity)
if not ok then
core.engine.print("error", err) -- 'connection timed out'
end
end):resume()local entity = util.promise.create()
entity:resolve(true)
core.engine.print("info", entity:reject("too late")) -- false