nupp.workers
Runs functions in parallel, on real threads.
A lane is reached through fork on a nupp.tasks scope: the scope hands the work to a pool of lanes and settles every child when the block ends.
module main
const jobs = require("jobs")
export function hashes(left: string, right: string): (string, string)
local first, second = "", ""
with scope = nupp.tasks.open() do
const one = scope:fork(left, jobs.hash)
const two = scope:fork(right, jobs.hash)
first, second = one:await(), two:await()
end
return first, second
endjobs.hash is an ordinary function. Calling it runs it here; handing it to fork runs it on a lane. There is no parallel version of it to write.
A lane is a thread with its own LuaJIT state, so the two sides never see each other's tables, globals, userdata, or module state. Ordinary arguments and results cross as copies. Immutable byte regions can share their backing storage, and native fixed-width heap arrays can move ownership instead. What may cross is the whole of what makes this safe, and the type says it. A function fork accepts is a @sendable function: a member of a loaded module, which carries no captures at all, or a literal whose captures are each initialized once, never reassigned, and copyable. The checker holds every capture to its declared type; what an any or a table turns out to hold is verified when the message is built, and a closure or a cycle found in there is refused at the fork, naming where it was.
This module selects the lane implementation and holds what generated code reaches; it has no scope of its own. nupp reference --section
sendable-callables is the whole rule, and Worker tasks is the guide.
Submodules
| Module | Description |
|---|---|
nupp.workers.spi | Shared interfaces for structured worker implementations. |
Module contents
Types
| Type | Kind | Description |
|---|---|---|
Submittable | type | What may actually be submitted: a module member, or an outlined literal whose effectively-final captures can be... |
Types#
Submittabletype#
type Submittable = function(...: any): anyWhat 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.