Skip to main content

Poll

A Poll represents the status of a Result, whether that result is Ready or Pending.

local poll = Poll.ok(...)
if poll:isReady() then
	local result = poll:unwrap()
	-- ...
elseif poll:isPending() then
	-- ...
end

Functions

ok

Poll.ok(...U...) → Poll<never,U...>

Creates a Poll with an Ok result.

err

Poll.err(errValueE) → Poll<E,never>

Creates a Poll with an Err result.

notReady

Poll.notReady() → Poll<never,never>

Creates a Poll which status is not ready.

isReady

Poll:isReady() → boolean

Checks whether the Result of a Poll is ready.

local poll = future:poll()
if poll:isReady() then
	local result = poll:unwrap()
	-- ...
end

isPending

Poll:isPending() → boolean

Checks whether the Result of a Poll is pending.

local poll = future:poll()
if poll:isPending() then
	continue
end

unwrap

Poll:unwrap() → Result<E,U...>

Checks whether the Result of a Poll is ready.

local poll = future:poll()
if poll:isReady() then
	local result = poll:unwrap()
	-- ...
else
	local result = poll:unwrap() --! Errors
	-- Error: Attempt to unwrap a pending future
end

Errors

TypeDescription
Attempt to unwrap a pending futureTo prevent this, use Poll:isReady() or Future:await() to ensure the Result is ready.
Show raw api
{
    "functions": [
        {
            "name": "isReady",
            "desc": "Checks whether the Result of a Poll is ready.\n```lua\nlocal poll = future:poll()\nif poll:isReady() then\n\tlocal result = poll:unwrap()\n\t-- ...\nend\n```\r",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean\r\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 55,
                "path": "src/Poll.luau"
            }
        },
        {
            "name": "isPending",
            "desc": "Checks whether the Result of a Poll is pending.\n```lua\nlocal poll = future:poll()\nif poll:isPending() then\n\tcontinue\nend\n```\r",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean\r\n"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 68,
                "path": "src/Poll.luau"
            }
        },
        {
            "name": "unwrap",
            "desc": "Checks whether the Result of a Poll is ready.\n```lua\nlocal poll = future:poll()\nif poll:isReady() then\n\tlocal result = poll:unwrap()\n\t-- ...\nelse\n\tlocal result = poll:unwrap() --! Errors\n\t-- Error: Attempt to unwrap a pending future\nend\n```\r",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Result<E, U...>\r\n"
                }
            ],
            "function_type": "method",
            "errors": [
                {
                    "lua_type": "Attempt to unwrap a pending future",
                    "desc": "To prevent this, use Poll:isReady() or Future:await() to ensure the Result is ready."
                }
            ],
            "source": {
                "line": 86,
                "path": "src/Poll.luau"
            }
        },
        {
            "name": "ok",
            "desc": "Creates a Poll with an `Ok` result.\r",
            "params": [
                {
                    "name": "...",
                    "desc": "",
                    "lua_type": "U..."
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Poll<never, U...>\r\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 101,
                "path": "src/Poll.luau"
            }
        },
        {
            "name": "err",
            "desc": "Creates a Poll with an `Err` result.\r",
            "params": [
                {
                    "name": "errValue",
                    "desc": "",
                    "lua_type": "E"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Poll<E, never>\r\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 114,
                "path": "src/Poll.luau"
            }
        },
        {
            "name": "notReady",
            "desc": "Creates a Poll which status is not ready.\r",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Poll<never, never>\r\n"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 127,
                "path": "src/Poll.luau"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "Poll",
    "desc": "A Poll represents the status of a [Result],\nwhether that result is Ready or Pending.\n```lua\nlocal poll = Poll.ok(...)\nif poll:isReady() then\n\tlocal result = poll:unwrap()\n\t-- ...\nelseif poll:isPending() then\n\t-- ...\nend\n```\r",
    "source": {
        "line": 25,
        "path": "src/Poll.luau"
    }
}