lloyAlloy on GitHub
Async and Futures
Docs

Async and Futures

async functions return a Future

Updated

The body runs on task.spawn under xpcall, and the Future memoizes the result. await yields until it settles. try await turns a failure into a Result.

Alloyasync.aly
1async function load(id: number): Profile
2    local raw = store:GetAsync(`p/{id}`)
3    return decode(raw)
4end
5async do
6    local profile = await load(1)
7    local safe = try await load(2)
8end
Emitted Luausame line count
1local __alloy = require("@alloy") local function load(id: number): __alloy.Future<Profile> return __alloy.future(function(): Profile
2    local raw = store:GetAsync(`p/{id}`)
3    return decode(raw)
4end) end
5__alloy.future(function()
6    local profile = __alloy.await(load(1))
7    local _1 = __alloy.try_await(load(2)) if _1.tag == "Err" then return _1 end local safe = _1._1
8end) return nil
  • The declared type is the inner one. async function f(): number is a Future<number> to callers; a missing type is inferred, and the hint offers the inner type.
  • async do ... end gives a Future from a block, Future.all, race, any, and all_settled combine them.
  • Hover shows Future<T>, never the runtime's table shape.