util.promise.create
Shared
Creates a new promise instance in pending state
Syntax
local instance = util.promise.create()A promise starts in a pending state and must be explicitly settled. Use self:resolve or self:reject to settle the promise, and thread:await inside a thread to retrieve the result.
- Resolved — the operation completed successfully; awaiting returns the resolved values.
- Rejected — the operation failed; awaiting throws with the rejection reason.
Parameters
| No parameters are accepted by this function |
|---|
Returns
| Type | Name | Description |
|---|---|---|
promise | instance | Created promise instance in a pending state |
Examples
local entity = util.promise.create()
entity:resolve(true, "done")local entity = util.promise.create()
util.thread.create(function(self)
local value = self:await(entity)
core.engine.print("info", value) -- 42
end):resume()
util.timer.create(function()
entity:resolve(42)
end, 1000, 1)