lloyAlloy on GitHub
Parallel Luau
Docs

Parallel Luau

Actor scripts, parallel blocks, and typed messages

Updated

A file named worker.server.actor.aly builds into an Actor. A parallel do block runs in the parallel phase, and the compiler refuses the writes the engine refuses. A message types both ends of SendMessage, and its reply comes back to any script.

Alloyparallel.aly
1export message Scan(parts: { BasePart }) reply(fallen: { BasePart })
2
3export function scan(parts: { BasePart }): { BasePart }
4    const fallen: { BasePart } = {}
5    parallel do
6        for _, part in parts do
7            if part.Position.Y < 0 then table.insert(fallen, part) end
8        end
9    end
10    return fallen
11end
Emitted Luausame line count
1local __alloy = require("@alloy") local Scan = __alloy.message("Scan", 1)
2
3local function scan(parts: { BasePart }): { BasePart }
4    const fallen: { BasePart } = {}
5    task.desynchronize() do
6        for _, part in parts do
7            if part.Position.Y < 0 then table.insert(fallen, part) end
8        end
9    task.synchronize() end
10    return fallen
11end return { Scan = Scan, scan = scan }
  • An actor script such as worker.server.actor.aly builds as the Actor worker with the Script inside. There, Scan.on(function(parts, respond) respond(scan(parts)) end) binds the handler.
  • The block keeps its lines: task.desynchronize() and task.synchronize() go on the lines of its header and its end.
  • The compiler refuses an Instance write that it can see, Instance.new, Destroy, Clone, await, and a return out of the block. It reads this file only, so the check is a guard rail, not a proof.
  • Scan.fire(worker, parts) sends from any script, and Scan.replied takes the answer in any script. as parallel runs a handler in the parallel phase.
  • The reference: actor, parallel, message, reply, and the reports ParallelError and ActorError.