Correlate asynchronous completions
app.handle · app.resolve · exact host payloadspending[RequestId] → resolve
The RequestId returned by a capability is the only reliable link between a later completion and the operation that started it.
When to use it
Use this for Host, Server, and Media requests that return RequestId.
- Store the intended operation immediately after receiving the RequestId.
- Clear the matching entry before decoding or mutating state so an error cannot leave it reusable.
- Ignore unknown IDs because they may be stale, duplicated, or belong to state that no longer exists.
- Use code for program decisions; message is bounded human-readable diagnostic context and must not be parsed.
Focused example
local pending: {[number]: string} = {}
local requestId = Host.storageGet("app-state")
pending[requestId] = "restore"
local function resolve(
id: number,
success: boolean,
payload: string,
code: string,
_message: string
)
local operation = pending[id]
pending[id] = nil
if operation == nil then return end
if not success then
status = operation .. " failed: " .. code
elseif operation == "restore" and not restore(payload) then
status = "Stored state is invalid"
end
end