Skip to main content

Promise

Promises, but without error handling as this screws with stack traces, using Roblox signals

See: https://promisesaplus.com/

Functions

isPromise

Promise.isPromise(valueany) → boolean

Determines whether a value is a promise or not.

new

Promise.new(func(
resolve(...) → (),
reject(...) → ()
) → ()?) → Promise<T>

Constructs a new promise.

::warning Do not yield within this func callback, as it will yield on the main thread. This is a performance optimization. ::

spawn

Promise.spawn(func(
resolve(...) → (),
reject(...) → ()
) → ()?) → Promise<T>

Initializes a new promise with the given function in a spawn wrapper.

delay

Promise.delay(
secondsnumber,
func(
resolve(...) → (),
reject(...) → ()
) → ()?
) → Promise<T>

Initializes a new promise with the given function in a delay wrapper.

defer

Promise.defer(func(
resolve(...) → (),
reject(...) → ()
) → ()?) → Promise<T>

Initializes a new promise with the given function in a deferred wrapper.

resolved

Promise.resolved(...Valuestoresolveto) → Promise<T>

Returns a resolved promise with the following values

rejected

Promise.rejected(...Valuestorejectto) → Promise<T>

Returns a rejected promise with the following values

IsPending

Promise:IsPending() → bool--

True if pending, false otherwise

Returns whether or not the promise is pending

IsFulfilled

Promise:IsFulfilled() → bool--

True if fulfilled

Returns whether or not the promise is fulfilled

IsRejected

Promise:IsRejected() → bool--

True if rejected

Returns whether or not the promise is rejected

Wait

This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. Yields
Promise:Wait() → T

Yields until the promise is complete, and errors if an error exists, otherwise returns the fulfilled results.

Yield

This is a yielding function. When called, it will pause the Lua thread that called the function until a result is ready to be returned, without interrupting other scripts. Yields
Promise:Yield() → boolean,T

Yields until the promise is complete, then returns a boolean indicating the result, followed by the values from the promise.

Resolve

Promise:Resolve(...T) → ()

Promise resolution procedure, resolves the given values

Reject

Promise:Reject(
...T--

Params to reject with

) → ()

Rejects the promise with the values given

Then

Promise:Then(
onFulfilledfunction,--

Called if/when fulfilled with parameters

onRejectedfunction--

Called if/when rejected with parameters

) → Promise<T>

Handlers if/when promise is fulfilled/rejected. It takes up to two arguments, callback functions for the success and failure cases of the Promise. May return the same promise if certain behavior is met.

info

We do not comply with 2.2.4 (onFulfilled or onRejected must not be called until the execution context stack contains only platform code). This means promises may stack overflow, however, it also makes promises a lot cheaper

If/when promise is rejected, all respective onRejected callbacks must execute in the order of their originating calls to then.

If/when promise is fulfilled, all respective onFulfilled callbacks must execute in the order of their originating calls to then.

Tap

Promise:Tap(
onFulfilledfunction,
onRejectedfunction
) → Promise<T>--

Returns self

Like then, but the value passed down the chain is the resolved value of the promise, not the value returned from onFulfilled or onRejected

Will still yield for the result if a promise is returned, but will discard the result.

Finally

Promise:Finally(funcfunction) → Promise<T>

Executes upon pending stop

Catch

Promise:Catch(onRejectedfunction) → Promise<T>

Catch errors from the promise

Destroy

Promise:Destroy() → ()

Rejects the current promise. Utility left for Maid task

GetResults

Promise:GetResults() → (
boolean,--

true if resolved, false otherwise.

any
)

Returns the results from the promise.

warning

This API surface will error if the promise is still pending.

Show raw api
{
    "functions": [
        {
            "name": "isPromise",
            "desc": "Determines whether a value is a promise or not.",
            "params": [
                {
                    "name": "value",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 27,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "new",
            "desc": "Constructs a new promise.\n\n::warning\nDo not yield within this func callback, as it will yield on the\nmain thread. This is a performance optimization.\n::",
            "params": [
                {
                    "name": "func",
                    "desc": "",
                    "lua_type": "(resolve: (...) -> (), reject: (...) -> ()) -> ()?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 42,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "spawn",
            "desc": "Initializes a new promise with the given function in a spawn wrapper.",
            "params": [
                {
                    "name": "func",
                    "desc": "",
                    "lua_type": "(resolve: (...) -> (), reject: (...) -> ()) -> ()?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 62,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "delay",
            "desc": "Initializes a new promise with the given function in a delay wrapper.",
            "params": [
                {
                    "name": "seconds",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "func",
                    "desc": "",
                    "lua_type": "(resolve: (...) -> (), reject: (...) -> ()) -> ()?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 77,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "defer",
            "desc": "Initializes a new promise with the given function in a deferred wrapper.",
            "params": [
                {
                    "name": "func",
                    "desc": "",
                    "lua_type": "(resolve: (...) -> (), reject: (...) -> ()) -> ()?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 94,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "resolved",
            "desc": "Returns a resolved promise with the following values",
            "params": [
                {
                    "name": "...",
                    "desc": "",
                    "lua_type": "Values to resolve to"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 109,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "rejected",
            "desc": "Returns a rejected promise with the following values",
            "params": [
                {
                    "name": "...",
                    "desc": "",
                    "lua_type": "Values to reject to"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 134,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "IsPending",
            "desc": "Returns whether or not the promise is pending",
            "params": [],
            "returns": [
                {
                    "desc": "True if pending, false otherwise",
                    "lua_type": "bool"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 151,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "IsFulfilled",
            "desc": "Returns whether or not the promise is fulfilled",
            "params": [],
            "returns": [
                {
                    "desc": "True if fulfilled",
                    "lua_type": "bool"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 160,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "IsRejected",
            "desc": "Returns whether or not the promise is rejected",
            "params": [],
            "returns": [
                {
                    "desc": "True if rejected",
                    "lua_type": "bool"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 169,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "Wait",
            "desc": "Yields until the promise is complete, and errors if an error\nexists, otherwise returns the fulfilled results.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "function_type": "method",
            "yields": true,
            "source": {
                "line": 180,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "Yield",
            "desc": "Yields until the promise is complete, then returns a boolean indicating\nthe result, followed by the values from the promise.",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean, T"
                }
            ],
            "function_type": "method",
            "yields": true,
            "source": {
                "line": 212,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "Resolve",
            "desc": "Promise resolution procedure, resolves the given values",
            "params": [
                {
                    "name": "...",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 244,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "Reject",
            "desc": "Rejects the promise with the values given",
            "params": [
                {
                    "name": "...",
                    "desc": "Params to reject with",
                    "lua_type": "T"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 322,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "Then",
            "desc": "Handlers if/when promise is fulfilled/rejected. It takes up to two arguments, callback functions\nfor the success and failure cases of the Promise. May return the same promise if certain behavior\nis met.\n\n:::info\nWe do not comply with 2.2.4 (onFulfilled or onRejected must not be called until the execution context stack\ncontains only platform code). This means promises may stack overflow, however, it also makes promises a lot cheaper\n:::\n\nIf/when promise is rejected, all respective onRejected callbacks must execute in the order of their\noriginating calls to then.\n\nIf/when promise is fulfilled, all respective onFulfilled callbacks must execute in the order of their\noriginating calls to then.",
            "params": [
                {
                    "name": "onFulfilled",
                    "desc": "Called if/when fulfilled with parameters",
                    "lua_type": "function"
                },
                {
                    "name": "onRejected",
                    "desc": "Called if/when rejected with parameters",
                    "lua_type": "function"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<T>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 392,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "Tap",
            "desc": "Like then, but the value passed down the chain is the resolved value of the promise, not\nthe value returned from onFulfilled or onRejected\n\nWill still yield for the result if a promise is returned, but will discard the result.",
            "params": [
                {
                    "name": "onFulfilled",
                    "desc": "",
                    "lua_type": "function"
                },
                {
                    "name": "onRejected",
                    "desc": "",
                    "lua_type": "function"
                }
            ],
            "returns": [
                {
                    "desc": "Returns self",
                    "lua_type": "Promise<T>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 416,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "Finally",
            "desc": "Executes upon pending stop",
            "params": [
                {
                    "name": "func",
                    "desc": "",
                    "lua_type": "function"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<T>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 448,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "Catch",
            "desc": "Catch errors from the promise",
            "params": [
                {
                    "name": "onRejected",
                    "desc": "",
                    "lua_type": "function"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<T>"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 458,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "Destroy",
            "desc": "Rejects the current promise. Utility left for Maid task",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 466,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "GetResults",
            "desc": "Returns the results from the promise.\n\n:::warning\nThis API surface will error if the promise is still pending.\n:::",
            "params": [],
            "returns": [
                {
                    "desc": "true if resolved, false otherwise.",
                    "lua_type": "boolean"
                },
                {
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 480,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        },
        {
            "name": "_executeThen",
            "desc": "",
            "params": [
                {
                    "name": "onFulfilled",
                    "desc": "",
                    "lua_type": "function?"
                },
                {
                    "name": "onRejected",
                    "desc": "",
                    "lua_type": "function?"
                },
                {
                    "name": "promise2",
                    "desc": "May be nil. If it is, then we have the option to return self",
                    "lua_type": "Promise<T>?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise"
                }
            ],
            "function_type": "method",
            "private": true,
            "source": {
                "line": 506,
                "path": "src/promise/src/Shared/Promise.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "Promise",
    "desc": "Promises, but without error handling as this screws with stack traces, using Roblox signals\n\nSee: https://promisesaplus.com/",
    "source": {
        "line": 8,
        "path": "src/promise/src/Shared/Promise.lua"
    }
}