Promise-Like Patterns
Implement deferred/promise objects using coroutines and callbacks.
What Is a Promise?
A promise represents a value that will be available in the future. It can be pending, fulfilled (with a value), or rejected (with an error).
Lua Promise Table
Implement a minimal promise as a table with state, value, and callback lists.
local function newPromise()
return {
state = "pending",
value = nil,
_resolve = {},
_reject = {},
}
end