Skip to content

st.promise — Promise Wrapper ​

Wraps a callback-based async function into a yielding call.

lua
-- Wraps a function that accepts a callback as its last argument
-- Pass "promiseReturnFunction" as a placeholder where the callback goes
local result1, result2 = st.promise.new(someAsyncFunction, arg1, arg2)

-- If the function expects the callback at a specific position:
local result = st.promise.new(function(arg, cb)
    someLib.doThing(arg, cb)
end, myArg, "promiseReturnFunction")