promise

A library that mostly implements Promise/A+ specification for GLua. If you are familiar with promises from JS, then this library will be easy to learn & use for you.

This library have a GLua module version.

Differences with JS Promises

  • Promises can be resolved immediately instead of being resolved in next tick (see Promise/A+ 3.1)

  • All functions are converted to PascalCase (JS -> Lua)

    • new Promise((resolve, reject) => {...}) -> promise.New(function(resolve, reject) ... end)

    • Promise.all(array) -> promise.All(array)

    • Promise.resolve(value) -> promise.Resolve(value)

    • Promise.reject(reason) -> promise.Reject(reason)

    • Promise.prototype.then(onFulfilled?, onRejected?) -> PromiseObject:Then(onFulfilled?, onRejected?)

    • Promise.prototype.catch(onRejected?) -> PromiseObject:Catch(onRejected?)

  • There currently no promise.AllSettled, promise.Any and PromiseObject:Finally(...) methods

  • Errors inside async will have error line prepended, see Notes for more information.

  • Errors doesn't have stacktrace

  • Since in lua we don't have syntax async function, async functions created using function promise.Async(function() ... end)

  • PromiseObject:Await() isn't safe to use, and throws errors. To handle errors and use await use PromiseObject:SafeAwait()

Last updated