autodoc_shared_functions
JO Functions > jo.promise.new()
Creates a new Promise that wraps a callback function <br> This utility transforms callback-style functions into Promise-returning functions <br>
JO Functions > jo.promise.new() > Syntax
jo.promise.new(cb, ...)
JO Functions > jo.promise.new() > Parameters
cb : function
The callback function to be wrapped in a Promise
... : mixed
Arguments to pass to the callback function
JO Functions > jo.promise.new() > Return Value
Type : ...
The resolved values from the Promise
JO Functions > jo.promise.new() > Example
-- Example: Convert a callback-based function to promise-based
local function fetchDataWithCallback(id, callback)
-- Simulate async operation
local id = "TheUniqueID"
jo.timeout.delay(id, 1000, function()
local result = { id = id, name = "Item " .. id }
callback(result)
end)
end
-- Using jo.promise to convert the callback to a promise
local result = jo.promise.new(function(resolver)
fetchDataWithCallback(123, resolver)
end)
-- Now 'result' contains the data directly, without needing a callback
print("Fetched item: " .. result.name)