Skip to content

Lua API Workers

Leonard Ramminger edited this page Aug 10, 2026 · 1 revision

Lua API — Workers (ctx:spawn, ctx:wait)

Run shell commands in the background inside a Lua step callback.

Only available in step({ run = function(ctx) ... end }).

ctx:spawn(options)

FieldRequiredType
cmdyesstring or { string, ... }
inputsnoglob list for cache inputs
outputsnoglob list for cache outputs
namenooverride auto name {step}-{n}

Returns: worker handle (number).

ctx:wait(handle [, options])

Wait for one worker. Pass an options table to select return fields:

OptionReturn field
exitCoderesult.exitCode
outputresult.output (captured stdout/stderr)
durationresult.duration
cachedresult.cached
nameresult.name
idresult.id
dryRunresult.dryRun

ctx:wait_all(handles [, options])

Same options for every handle. Returns 1-based array of result tables in handle order.

Example

step({
name="compile",
phase="build",
scope="cpp",
run=function(ctx)
localjobs= {}
for_, srcinipairs(beez.fs.glob("src/**/*.cpp")) dojobs[#jobs+1] =ctx:spawn({ cmd="g++ -c " ..src })
endfor_, resultinipairs(ctx:wait_all(jobs, { exitCode=true })) doifresult.exitCode~=0thenerror("compile failed") endendreturn0end,
})

Full reference: docs/worker-api.md


← Lua API Overview

Clone this wiki locally