Skip to main content

PromiseUtils

Utility methods for promise

Functions

any

PromiseUtils.any(promises{Promise<T...>}) → Promise<T...>--

Promise that settles with the first result

Settles with the first of the given promises to settle, resolving if it resolved or rejecting if it rejected. Also available as PromiseUtils.race.

race

PromiseUtils.race(promises{Promise<T...>}) → Promise<T...>

Alias for PromiseUtils.any. Settles with the first of the given promises to settle, resolving if it resolved or rejecting if it rejected.

delayed

PromiseUtils.delayed(secondsnumber) → Promise

Returns a promise that will resolve after the set amount of seconds

all

PromiseUtils.all(promises{Promise<T>}) → Promise<T>

Executes all promises. If any fails, the result will be rejected. However, it yields until every promise is complete.

WARNING

Passing in a spare array (i.e. {nil, promise}) will result in undefined behavior here.

firstSuccessOrLastFailure

PromiseUtils.firstSuccessOrLastFailure(promises{Promise<T>}) → Promise.Promise<T...>

Keeps on trying promises until one of them succeeds, or reports the last failure.

combine

PromiseUtils.combine(stateTableany) → Promise<any>

Combines the result of promises together

invert

PromiseUtils.invert(promisePromise<T>) → Promise<T>

Inverts the result of a promise, turning a resolved promise into a rejected one, and a rejected one into a resolved one.

fromSignal

PromiseUtils.fromSignal(signalSignal<T>) → Promise<T>

Creates a promise from a signal

timeout

PromiseUtils.timeout(
timeoutTimenumber,
fromPromisePromise<T>
) → Promise<T>

Creates a new promise from the given promise that will reject after the given timeoutTime

Show raw api
{
    "functions": [
        {
            "name": "any",
            "desc": "Settles with the first of the given promises to settle, resolving if it resolved or rejecting if\nit rejected. Also available as [PromiseUtils.race].",
            "params": [
                {
                    "name": "promises",
                    "desc": "",
                    "lua_type": "{ Promise<T...> }"
                }
            ],
            "returns": [
                {
                    "desc": "Promise that settles with the first result",
                    "lua_type": "Promise<T...>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 21,
                "path": "src/promise/src/Shared/PromiseUtils.lua"
            }
        },
        {
            "name": "race",
            "desc": "Alias for [PromiseUtils.any]. Settles with the first of the given promises to settle, resolving\nif it resolved or rejecting if it rejected.",
            "params": [
                {
                    "name": "promises",
                    "desc": "",
                    "lua_type": "{ Promise<T...> }"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<T...>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 48,
                "path": "src/promise/src/Shared/PromiseUtils.lua"
            }
        },
        {
            "name": "delayed",
            "desc": "Returns a promise that will resolve after the set amount of seconds",
            "params": [
                {
                    "name": "seconds",
                    "desc": "",
                    "lua_type": "number"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 56,
                "path": "src/promise/src/Shared/PromiseUtils.lua"
            }
        },
        {
            "name": "all",
            "desc": "Executes all promises. If any fails, the result will be rejected. However, it yields until\nevery promise is complete.\n\n:::warning\nPassing in a spare array (i.e. {nil, promise}) will result in undefined behavior here.\n:::",
            "params": [
                {
                    "name": "promises",
                    "desc": "",
                    "lua_type": "{ Promise<T> }"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 75,
                "path": "src/promise/src/Shared/PromiseUtils.lua"
            }
        },
        {
            "name": "firstSuccessOrLastFailure",
            "desc": "Keeps on trying promises until one of them succeeds, or reports\nthe last failure.",
            "params": [
                {
                    "name": "promises",
                    "desc": "",
                    "lua_type": "{ Promise<T> }"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise.Promise<T...>\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 112,
                "path": "src/promise/src/Shared/PromiseUtils.lua"
            }
        },
        {
            "name": "combine",
            "desc": "Combines the result of promises together",
            "params": [
                {
                    "name": "stateTable",
                    "desc": "",
                    "lua_type": "any"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<any>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 151,
                "path": "src/promise/src/Shared/PromiseUtils.lua"
            }
        },
        {
            "name": "invert",
            "desc": "Inverts the result of a promise, turning a resolved promise\ninto a rejected one, and a rejected one into a resolved one.",
            "params": [
                {
                    "name": "promise",
                    "desc": "",
                    "lua_type": "Promise<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 201,
                "path": "src/promise/src/Shared/PromiseUtils.lua"
            }
        },
        {
            "name": "fromSignal",
            "desc": "Creates a promise from a signal",
            "params": [
                {
                    "name": "signal",
                    "desc": "",
                    "lua_type": "Signal<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 224,
                "path": "src/promise/src/Shared/PromiseUtils.lua"
            }
        },
        {
            "name": "timeout",
            "desc": "Creates a new promise from the given promise that will\nreject after the given `timeoutTime`",
            "params": [
                {
                    "name": "timeoutTime",
                    "desc": "",
                    "lua_type": "number"
                },
                {
                    "name": "fromPromise",
                    "desc": "",
                    "lua_type": "Promise<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 250,
                "path": "src/promise/src/Shared/PromiseUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "PromiseUtils",
    "desc": "Utility methods for promise",
    "source": {
        "line": 6,
        "path": "src/promise/src/Shared/PromiseUtils.lua"
    }
}