nupp.workers.spi

Shared interfaces for structured worker implementations.

The workers module selects an implementation during initialization. A provider owns its lane scheduler, but uses the canonical Scope, Task, Status, and submitted-signature types declared here. A scope is reached only through a task scope's fork, which owns one privately. Generic spawn must preserve the exact argument and result packs of the sendable function.

Arguments and results cross isolated Lua states as copies. Only explicitly supported engine-backed affine owners move; arbitrary closures, pointers, coroutines, and Lua-owned affine resources cannot be copied as task arguments. Runtime validation must also reject unsupported value graphs that static types cannot exclude. A task's result count preserves embedded and trailing nil values. await returns that exact pack or raises failure/cancellation; isDone reports terminal settlement, status reports scheduler state, and cancel reports whether it made the first cancellation request.

Scope cleanup settles all children, including those never awaited, before propagating unobserved failure. Cancellation uses nupp.runtime.cancellation. Blocking waits cooperate with the selected suspension implementation and must not discover implementations during settlement.

Each lane uses the artifact's immutable SPI index and loads independent module instances. Provider objects and Lua closures are never transferred between lanes.

Module contents

Types

TypeKindDescription
ProviderinterfaceComplete worker implementation protocol, including structured-task integration.
ScoperecordA family of parallel child tasks, owned by the task scope whose fork opened it.
StatustypeWhere a task is: waiting to start, running, or settled one of three ways.
SubmittabletypeWhat may actually be submitted: a module member, or an outlined literal whose effectively-final captures can be...
TasktypeThe typed handle for one started function, which nupp.tasks names Task.

Functions

FunctionKindDescription
Submittedcomptime functionThe arguments a submitted function takes, once its whole signature is known to be copyable.

Types#

Providerinterface#

interface Provider ...

Complete worker implementation protocol, including structured-task integration. Implement generic spawn and ownership guarantees through the shared scope types.

Members

NameKindDescription
priorityfield
openScopemethodCreates canonical scope state for task integration, with an optional monotonic deadline and observer.
settlemethodWaits for a task and returns status, packed values, exact count, and problem.
runSchedulermethodRuns provider scheduler progress using its retained lane state.
defineSendablemethodAssociates an executable function with its module/member identity.
describeSendablemethodDescribes a submitted function and captures for destination-lane execution.

priorityfield#

priority: integer?
@readonly

openScopemethod#

openScope: function(deadline: number?, observer: any): Scope
@readonly

Creates canonical scope state for task integration, with an optional monotonic deadline and observer.

Arguments
NameTypeDescription
deadlinenumber?
observerany
Returns
TypeDescription
Scope

settlemethod#

settle: function(task: any): (string, {any}?, integer, any)
@readonly

Waits for a task and returns status, packed values, exact count, and problem. Status is done, failed, or cancelled; cancellation preserves its shared identity.

Arguments
NameTypeDescription
taskany
Returns
TypeDescription
string
{any}?
integer
any

runSchedulermethod#

runScheduler: function(): nil
@readonly

Runs provider scheduler progress using its retained lane state.

Returns
TypeDescription
nil

defineSendablemethod#

defineSendable: function(moduleName: string, member: string, fn: any): nil
@readonly

Associates an executable function with its module/member identity.

Arguments
NameTypeDescription
moduleNamestring
memberstring
fnany
Returns
TypeDescription
nil

describeSendablemethod#

describeSendable: function(fn: any, moduleName: string, member: string, ...: any): any
@readonly

Describes a submitted function and captures for destination-lane execution.

Arguments
NameTypeDescription
fnany
moduleNamestring
memberstring
...any
Returns
TypeDescription
any

Scoperecord#

record Scope ...

A family of parallel child tasks, owned by the task scope whose fork opened it.

Members

NameKindDescription
spawnmethodStarts one sendable function with copied arguments.
closemethodWaits for every child, raising the first failure nothing observed.

spawnmethod#

spawn: function<F is Submittable>(borrows self: Scope, ...: unpackof Submitted(F), F): Task<F>

Starts one sendable function with copied arguments.

Arguments
NameTypeDescription
borrows selfScope
...unpackof Submitted(F)
?F
Returns
TypeDescription
Task<F>

closemethod#

close: function(borrows self: Scope): nil

Waits for every child, raising the first failure nothing observed. Idempotent. Under a suspension handler it parks until every child has settled, and without one it blocks.

Arguments
NameTypeDescription
borrows selfScope
Returns
TypeDescription
nil

Statustype#

type Status = "queued" | "running" | "done" | "failed" | "cancelled"

Where a task is: waiting to start, running, or settled one of three ways.

A closed union, so a switch over it needs no else. nupp.tasks names it Status.

Submittabletype#

type Submittable = @sendable function(...: any): any

What may actually be submitted: a module member, or an outlined literal whose effectively-final captures can be copied to another lane. Exported so a task scope can hold its fork to the same bound without linking this module.

Tasktype#

type Task<F> = TaskType(F)

The typed handle for one started function, which nupp.tasks names Task<F>.

Its await result pack is the function's, which is why this is derived from the function type rather than declared once over any. status answers a nupp.workers.spi.Status.

Type parameters

NameDescription
F

Functions#

Submittedcomptime function#

@comptime function Submitted(F: type): typepack
@comptime

The arguments a submitted function takes, once its whole signature is known to be copyable. Reached only from spawn: naming Task<F> describes a handle rather than a crossing, so a signature is held to this where it is submitted and nowhere else.

Arguments

NameTypeDescription
Ftype

Returns

TypeDescription
typepack