nupp.host.pump
nupp.host.pump runs one operation at a time for an application that embeds the runtime and owns its own loop. Reach for it from the exports such an application calls, so that an operation which waits -- on a nupp.host request, a timer, the network -- parks instead of blocking the call that started it.
start runs an operation until it finishes or parks, and says which; the application keeps calling poll from its loop, after answering whatever it was asked, until the operation finishes. Each poll is one non-blocking pass over the runtime's readiness sources, and an operation they make ready resumes inside that pass.
local pump = nupp.host.pump
local session = pump.newPump()
export function frame(dt: number): pump.State
if session:parked() then
return session:poll()
end
return session:start(function(): boolean
return update(dt)
end)
endAn operation returns whether the application should keep running: false reports "stopped", anything else "continue". A failure is raised from the start or poll that observes it. cancel unwinds a parked operation, raising a cancellation inside it, so its cleanup runs before the application shuts down.
Module contents
Types
| Type | Kind | Description |
|---|---|---|
Pump | record | Runs one parked operation at a time for a host-owned loop. |
State | type | What a start or poll left the operation doing. |
Functions
| Function | Kind | Description |
|---|---|---|
newPump | function | Creates an idle pump. |
Types#
Pumprecord#
record Pump ...Runs one parked operation at a time for a host-owned loop.
Members
| Name | Kind | Description |
|---|---|---|
handler | field | |
active | field | |
result | field | |
failure | field | |
start | method | Runs body until it finishes or parks. |
poll | method | Makes one non-blocking pass over the readiness sources, resuming the parked operation if they make it ready. |
parked | method | Whether an operation is parked between the host's turns. |
cancel | method | Unwinds a parked operation, raising a cancellation inside it. |
startmethod#
Runs body until it finishes or parks.
Arguments
| Name | Type | Description |
|---|---|---|
self | Pump | |
body | function(): boolean? |
Returns
| Type | Description |
|---|---|
State |
Raises
| Type | Condition |
|---|---|
string | when another operation is still parked, or what |
pollmethod#
Makes one non-blocking pass over the readiness sources, resuming the parked operation if they make it ready.
Arguments
| Name | Type | Description |
|---|---|---|
self | Pump |
Returns
| Type | Description |
|---|---|
State |
Raises
| Type | Condition |
|---|---|
string | when nothing is parked, or what the operation raised |
Statetype#
type State = "parked" | "continue" | "stopped"What a start or poll left the operation doing.
Functions#
newPumpfunction#
function newPump(): PumpCreates an idle pump.
Returns
| Type | Description |
|---|---|
Pump |