self:resolve

Shared

Resolves the promise with the given values, resuming any threads awaiting it


Syntax

local status = self:resolve(
    ...
)

A promise can only be settled once. Calling self:resolve or self:reject on an already-settled promise has no effect and returns false.

  • Pending — the promise is resolved and all awaiting threads are resumed with the provided values.
  • Already settled — the call is ignored and false is returned.

Parameters

TypeNameDescription
any...One or more values to resolve the promise with

Returns

TypeNameDescription
boolstatustrue if the promise was successfully resolved, false if it was already settled

Examples

Resolve a promise with a single value
local entity = util.promise.create()

entity:resolve(true)
Resolve a promise and retrieve the value from a thread
local entity = util.promise.create()

entity:resolve("hello", "world")

util.thread.create(function(self)
    local a, b = self:await(entity)
    core.engine.print("info", a, b) -- 'hello'  'world'
end):resume()
Attempt to resolve an already-settled promise
local entity = util.promise.create()

entity:resolve(true)
core.engine.print("info", entity:resolve(false)) -- false

On this page