nupp.suspension.spi
Shared interfaces for scheduler integration.
Importing these declarations initializes no scheduler. The facade retains the selected functions. Source, Context, Waiting, Handler, and Installed are the shared types; providers initialize these declarations or satisfy their exact signatures without replacing their nominal identities.
Each record declares what its holder may read and nothing else. Whatever state an implementation needs beside that is its own, kept where callers cannot reach it, so two implementations may represent a source or an installation differently and neither has to reproduce the other's layout.
A subscription may resume synchronously or later. It must settle a Waiting only once and run returned cleanup when the wait ends, including cancellation. Waiting.onResume is settle-safe: registering a waker on a wait that has already settled runs it immediately. Source release and Installed close must not suspend. Nested installation restores the captured handler, and a driver installation preserves delegation to the outer scheduler. create propagates the suspension context into a new coroutine.
Sources report readiness in order, lowest first. Context.uses identifies sources needed by a wait. Whether a park is permitted here is canSuspend, which returns for the handler in force. Cancellation values must come from nupp.suspension.cancellation, which preserves recognition by tasks and worker providers. State belongs to one Lua state; registrations and handlers are not copied into worker lanes.
Module contents
Types
| Type | Kind | Description |
|---|---|---|
Context | record | Subscription context used to register or associate readiness sources. |
Create | type | Coroutine construction preserving arbitrary argument and result packs. |
Handler | record | Scheduler integration operations with explicit Handler receivers. |
Installed | record | Handler restoration state owned by an installation. |
Provider | interface | |
Source | record | Readiness registration shared with callers and handlers. |
Suspend | type | Typed subscription operation preserving the result type T. |
Waiting | record | A single pending operation observed by a suspension handler. |
Types#
Contextrecord#
record Context ...Subscription context used to register or associate readiness sources. A subscription may use an existing Source or create a scoped one.
Members
| Name | Kind | Description |
|---|---|---|
source | method | Registers a source associated with this subscription, as nupp.suspension.spi.Provider.source registers one outside any. |
uses | method | Associates an existing source with this wait without changing its identity. |
sourcemethod#
source: function(
self: Context,
name: string,
order: integer,
poll: function(): integer,
wait: (function(integer): integer)?,
active: (function(source: Source): boolean)?
): SourceRegisters a source associated with this subscription, as nupp.suspension.spi.Provider.source registers one outside any.
Arguments
| Name | Type | Description |
|---|---|---|
self | Context | |
name | string | |
order | integer | |
poll | function(): integer | |
wait | (function(integer): integer)? | |
active | (function(source: Source): boolean)? |
Returns
| Type | Description |
|---|---|
Source |
Createtype#
type Create = function<A..., R...>(body: function(A...): R...): threadCoroutine construction preserving arbitrary argument and result packs.
Handlerrecord#
record Handler ...Scheduler integration operations with explicit Handler receivers. park drives or yields a wait; shutdown releases handler-owned scheduling state.
Members
| Name | Kind | Description |
|---|---|---|
park | method | Parks or drives this Waiting; cleanup cancels the subscription. |
canPark | method | Reports whether this handler can park the current execution. |
shutdown | method | Releases scheduling state owned by this handler. |
parkmethod#
Parks or drives this Waiting; cleanup cancels the subscription.
Arguments
| Name | Type | Description |
|---|---|---|
self | Handler | |
waiting | Waiting | |
cleanup | function(): nil |
Returns
| Type | Description |
|---|---|
nil |
Installedrecord#
Handler restoration state owned by an installation. Closing it restores the outer context and releases registration state.
Members
| Name | Kind | Description |
|---|---|---|
close | method | Restores the outer handler and settles every park this installation accepted, without suspending. |
handler | field | Handler supplied by the caller. |
Providerinterface#
interface Provider ...Members
| Name | Kind | Description |
|---|---|---|
priority | field | |
source | method | Registers a named poll source with a poll order and optional blocking waiter. |
poll | method | Polls registered sources and returns the amount of progress reported. |
suspend | field | Subscribes once, then waits for a typed result through the active handler. |
install | method | Installs a host's handler and returns affine restoration state. |
installDriver | method | Installs a driver's handler, which stands in front of a host rather than being one: a task scope opened in a frame... |
create | field | Creates a coroutine preserving the active suspension context and result pack. |
handled | method | Reports whether an installed handler owns the current suspension context. |
canSuspend | method | Reports whether this execution context can perform a suspension. |
delegatedCanPark | method | Captures the barrier in force here, for a driver about to displace it. |
delegatedPark | method | Captures how a wait is parked here, for a driver about to displace it. |
derive | method | Builds a Waiting that settles when base does or when ready returns true. |
turnAvailable | field | Whether the aggregate running here may spend another coroutine activation before it owes its host a turn. |
consumeTurn | field | Records one coroutine activation against the current turn. |
deferTurn | field | Parks until the host has had its turn. |
sourcemethod#
source: function(
name: string,
order: integer,
poll: function(): integer,
wait: (function(integer): integer)?,
active: (function(Source): boolean)?
): SourceRegisters a named poll source with a poll order and optional blocking waiter. The optional active predicate controls whether the source can make progress.
Arguments
| Name | Type | Description |
|---|---|---|
name | string | |
order | integer | |
poll | function(): integer | |
wait | (function(integer): integer)? | |
active | (function(Source): boolean)? |
Returns
| Type | Description |
|---|---|
Source |
pollmethod#
poll: function(): integerPolls registered sources and returns the amount of progress reported.
Returns
| Type | Description |
|---|---|
integer |
suspendfield#
suspend: SuspendSubscribes once, then waits for a typed result through the active handler.
installmethod#
Installs a host's handler and returns affine restoration state.
Arguments
| Name | Type | Description |
|---|---|---|
handler | Handler |
Returns
| Type | Description |
|---|---|
affine(Installed) |
installDrivermethod#
Installs a driver's handler, which stands in front of a host rather than being one: a task scope opened in a frame installs one so the frame's own waits keep its children running, and it does not bound a host turn where no host is beneath it.
Arguments
| Name | Type | Description |
|---|---|---|
handler | Handler |
Returns
| Type | Description |
|---|---|
affine(Installed) |
createfield#
Creates a coroutine preserving the active suspension context and result pack.
handledmethod#
handled: function(): booleanReports whether an installed handler owns the current suspension context.
Returns
| Type | Description |
|---|---|
boolean |
canSuspendmethod#
canSuspend: function(): booleanReports whether this execution context can perform a suspension.
Returns
| Type | Description |
|---|---|
boolean |
delegatedCanParkmethod#
delegatedCanPark: function(): function(): booleanCaptures the barrier in force here, for a driver about to displace it.
A driver's handler changes where a branch yields and must not quietly grant permission the handler it displaced refused, so a driver takes this before it installs and delegates canPark to it. Resolved when called rather than where captured, because a host enters and leaves barriers while a driver is live.
Returns
| Type | Description |
|---|---|
function(): boolean |
delegatedParkmethod#
delegatedPark: function(): function(Waiting, function(): nil): nilCaptures how a wait is parked here, for a driver about to displace it.
A driver runs its own work while a frame waits and hands what it cannot satisfy to the handler it displaced, or to the blocking park where there is none. Captured like delegatedCanPark, and resolved when called.
Returns
| Type | Description |
|---|---|
function(Waiting, function(): nil): nil |
derivemethod#
derive: function(
base: Waiting,
ready: function(): boolean,
arm: function(wake: function(): nil): nil
): WaitingBuilds a Waiting that settles when base does or when ready returns true.
A driver parks outward on the result, so the park it hands to its host is woken both by the wait it was given and by its own work becoming runnable. arm registers the driver's own wakers and receives the same callback base is armed with, which runs at most once per registration. Whatever routing state base carries travels with the derived wait, so a blocking park on it reaches the readiness sources the original named.
Arguments
| Name | Type | Description |
|---|---|---|
base | Waiting | |
ready | function(): boolean | |
arm | function(wake: function(): nil): nil |
Returns
| Type | Description |
|---|---|
Waiting |
turnAvailablefield#
turnAvailable: (function(): boolean)?Whether the aggregate running here may spend another coroutine activation before it owes its host a turn.
Turn budgeting is an implementation's to offer: absent, the three leave the aggregate turn unbounded, and the facade supplies that reading. An implementation publishes all three or none.
consumeTurnfield#
consumeTurn: (function(): nil)?Records one coroutine activation against the current turn.
Sourcerecord#
record Source ...Readiness registration shared with callers and handlers. release must be idempotent and non-suspending; provider state tracks its lifetime.
Members
| Name | Kind | Description |
|---|---|---|
release | method | Unregisters this source without suspending; repeated calls are harmless. |
name | field | Diagnostic identity of the readiness source. |
order | field | Where in a poll pass this source runs; smaller orders are polled first. |
wait | field | Optional bounded blocking waiter receiving milliseconds and returning progress. |
active | field | Optional predicate deciding whether the source has outstanding work. |
releasemethod#
Unregisters this source without suspending; repeated calls are harmless. The provider supplies it with the registration.
Arguments
| Name | Type | Description |
|---|---|---|
self | Source |
Returns
| Type | Description |
|---|---|
nil |
waitfield#
wait: (function(integer): integer)?Optional bounded blocking waiter receiving milliseconds and returning progress.
Suspendtype#
type Suspend = function<T>(operation: string, subscribe: function(function(T), Context): (function()?)): TTyped subscription operation preserving the result type T. The subscription returns optional cleanup and may resume synchronously.
Waitingrecord#
record Waiting ...A single pending operation observed by a suspension handler. ready is monotonic once resumed; onResume installs the handler's wake callback.
Members
| Name | Kind | Description |
|---|---|---|
ready | method | Reports whether the subscription has settled. |
onResume | method | Registers a wake callback for the waiting scheduler. |
operation | field | Diagnostic operation name supplied to suspend. |
readymethod#
ready: function(self: Waiting): booleanReports whether the subscription has settled.
Arguments
| Name | Type | Description |
|---|---|---|
self | Waiting |
Returns
| Type | Description |
|---|---|
boolean |
onResumemethod#
onResume: function(self: Waiting, wake: function(): nil): nilRegisters a wake callback for the waiting scheduler.
Settle-safe: where the wait has already settled, wake is called before this returns rather than stored. A handler may therefore arm once and then yield until ready returns true, without a recheck loop around the arming.
Arguments
| Name | Type | Description |
|---|---|---|
self | Waiting | |
wake | function(): nil |
Returns
| Type | Description |
|---|---|
nil |