⌂ Modules Module: nupp Module: nupp.workers Module: nupp.workers
Isolated worker threads.
Each worker owns a fresh LuaJIT state on a native thread. Values cross only as bounded string.buffer messages, so neither Lua heap, module state, globals, closures, userdata, nor cdata are shared.
Worker entry modules run from the same stamped payload as their spawner:
The entry obtains its endpoints independently:
A ready receive returns inline. A wait blocks efficiently in an ordinary program and suspends under an installed handler. Closing is cooperative: it wakes a worker blocked in Self:receive, but source that ignores the closed inbox can keep join and stop waiting indefinitely.
Module contents Types Type Kind Description Exitrecord How a worker ended. Selfrecord The worker-side endpoints. Workerrecord A fresh Lua state running on a native thread.
Functions
Types
Exitrecord
How a worker ended.
Fields Name Type Description succeededboolean True when the entry module returned without an uncaught error.
statusinteger Zero for a clean return and nonzero for a load or runtime failure.
errorstring ? The worker's load or runtime error, when it failed.
Selfrecord
The worker-side endpoints.
Methods
receive
Waits for and returns the next payload. Nil means the inbox closed and drained.
receive : function ( workers . Self ) : any ?
Arguments Name Type Description ?workers . Self
Returns
send
Sends an ordinary message to the spawner.
send : function ( workers . Self , any )
Arguments Name Type Description ?workers . Self ?any
serve
Answers requests until the inbox closes.
serve : function ( workers . Self , function ( any ) : any )
Arguments Name Type Description ?workers . Self ?function ( any ) : any
Fields Name Type Description inboxChannel outboxChannel
Workerrecord
A fresh Lua state running on a native thread.
record workers . Worker
_handle : any
_inbox : Channel
_outbox : Channel
_closed : boolean
_destroyed : boolean
_exit : workers . Exit ?
_nextId : integer
_pendingIds : { [ integer ] : boolean }
_replies : { [ integer ] : Frame }
_messages : { any }
_firstMessage : integer
_lastMessage : integer
send : function ( workers . Worker , any )
tryReceive : function ( workers . Worker ) : any ?
receive : function ( workers . Worker , integer ? ) : any ?
call : function ( workers . Worker , any ) : any
close : function ( workers . Worker )
join : function ( workers . Worker ) : workers . Exit
stop : function ( workers . Worker ) : workers . Exit
end
Methods
send
Queues a copied value without waiting for capacity.
send : function ( workers . Worker , any )
Arguments Name Type Description ?workers . Worker ?any
tryReceive
Takes a ready ordinary message without waiting.
tryReceive : function ( workers . Worker ) : any ?
Arguments Name Type Description ?workers . Worker
Returns
receive
Waits for an ordinary message, or up to timeoutMs when supplied.
receive : function ( workers . Worker , integer ? ) : any ?
Arguments Name Type Description ?workers . Worker ?integer ?
Returns
call
Sends a request and waits for the matching reply.
call : function ( workers . Worker , any ) : any
Arguments Name Type Description ?workers . Worker ?any
Returns
close
Closes the worker inbox. Nonblocking and idempotent.
close : function ( workers . Worker )
Arguments Name Type Description ?workers . Worker
join
Waits for the worker thread and records how it ended.
Arguments Name Type Description ?workers . Worker
Returns Type Description workers . Exit
stop
Closes, joins, and releases the worker. Idempotent.
Arguments Name Type Description ?workers . Worker
Returns Type Description workers . Exit
Functions
workers.currentfunction
Returns the endpoints installed in the current worker state.
Returns Type Description workers . Self
Raises
workers.Self:receivemethod
function workers . Self : receive ( ) : any ?
Returns
workers.Self:sendmethod
function workers . Self : send ( value : any ) : nil
Arguments Name Type Description valueany
Returns
workers.Self:servemethod
function workers . Self : serve ( handler : function ( any ) : any ) : nil
Arguments Name Type Description handlerfunction ( any ) : any
Returns
workers.spawnfunction
Starts entry in a fresh LuaJIT state.
Arguments Name Type Description entrystring
Returns Type Description workers . Worker an owned worker that is stopped on every structured exit
workers.Worker:callmethod
function workers . Worker : call ( value : any ) : any
Arguments Name Type Description valueany
Returns
workers.Worker:closemethod
function workers . Worker : close ( ) : nil
Returns
workers.Worker:joinmethod
Returns Type Description workers . Exit
workers.Worker:receivemethod
function workers . Worker : receive ( timeoutMs : integer ? ) : any ?
Arguments Name Type Description timeoutMsinteger ?
Returns
workers.Worker:sendmethod
function workers . Worker : send ( value : any ) : nil
Arguments Name Type Description valueany
Returns
workers.Worker:stopmethod
Returns Type Description workers . Exit
workers.Worker:tryReceivemethod
function workers . Worker : tryReceive ( ) : any ?
Returns
← Previous Module: nupp.suspension Next → Module: nupp.zone