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.

A subscription may resume synchronously or later. It must settle a Waiting only once and run returned cleanup when the wait ends, including cancellation. Source release and Installed close must not suspend. Nested installation restores the captured handler, and transparent handlers preserve delegation to the outer scheduler. create propagates the suspension context into a new coroutine.

Beside the interface, an implementation publishes two hooks with rawset: __delegatedCanPark and __delegatedPark each capture, where they are called, the handler an installation is about to displace, and answer that handler's canPark and park later. A task scope's driver defers to its host through them. The facade refuses an implementation without both.

Sources report readiness in order, lowest first. Context.uses identifies sources needed by a wait, while canPark distinguishes schedulers that can yield from ones that must drive readiness themselves. Cancellation values must come from nupp.runtime.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

TypeKindDescription
ContextrecordSubscription context used to register or associate readiness sources.
CreatetypeCoroutine construction preserving arbitrary argument and result packs.
HandlerrecordScheduler integration operations with explicit Handler receivers.
InstalledrecordHandler restoration state owned by one installation.
Providerinterface
SourcerecordReadiness registration shared with callers and handlers.
SuspendtypeTyped subscription operation preserving the result type T.
WaitingrecordA 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

NameKindDescription
sourcemethodRegisters a source associated with this subscription, as nupp.suspension.spi.Provider.source registers one outside any.
usesmethodAssociates an existing source with this wait without changing its identity.
canParkmethodReports whether the current handler can park this subscription.

sourcemethod#

source: function(
    self: Context,
    name: string,
    order: integer,
    poll: function(): integer,
    wait: (function(integer): integer)?,
    active: (function(source: Source): boolean)?
): Source

Registers a source associated with this subscription, as nupp.suspension.spi.Provider.source registers one outside any.

Arguments
NameTypeDescription
selfContext
namestring
orderinteger
pollfunction(): integer
wait(function(integer): integer)?
active(function(source: Source): boolean)?
Returns
TypeDescription
Source

usesmethod#

uses: function(self: Context, source: Source): nil

Associates an existing source with this wait without changing its identity.

Arguments
NameTypeDescription
selfContext
sourceSource
Returns
TypeDescription
nil

canParkmethod#

canPark: function(self: Context): boolean

Reports whether the current handler can park this subscription.

Arguments
NameTypeDescription
selfContext
Returns
TypeDescription
boolean

Createtype#

type Create = function<A..., R...>(body: function(A...): R...): thread

Coroutine 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

NameKindDescription
parkmethodParks or drives this Waiting; cleanup cancels the subscription.
canParkmethodReports whether this handler can park the current execution.
shutdownmethodReleases scheduling state owned by this handler.

parkmethod#

park: function(self: Handler, waiting: Waiting, cleanup: function(): nil): nil

Parks or drives this Waiting; cleanup cancels the subscription.

Arguments
NameTypeDescription
selfHandler
waitingWaiting
cleanupfunction(): nil
Returns
TypeDescription
nil

canParkmethod#

canPark: function(self: Handler): boolean

Reports whether this handler can park the current execution.

Arguments
NameTypeDescription
selfHandler
Returns
TypeDescription
boolean

shutdownmethod#

shutdown: function(self: Handler): nil

Releases scheduling state owned by this handler.

Arguments
NameTypeDescription
selfHandler
Returns
TypeDescription
nil

Installedrecord#

record Installed is nupp.Closeable ...

Handler restoration state owned by one installation. Closing it restores the outer context and releases registration state.

Members

NameKindDescription
closemethodRestores the outer handler and settles every park this installation accepted, without suspending.
handlerfieldHandler supplied by the caller.
transparentfieldWhether operations may delegate through to the outer context.

closemethod#

close: @nosuspend function(takes self: Installed): nil

Restores the outer handler and settles every park this installation accepted, without suspending. The provider supplies it with the installation; a drain that fails leaves the installation to be closed again.

Arguments
NameTypeDescription
takes selfInstalled
Returns
TypeDescription
nil

handlerfield#

handler: Handler

Handler supplied by the caller.

transparentfield#

transparent: boolean

Whether operations may delegate through to the outer context.

Providerinterface#

interface Provider ...

Members

NameKindDescription
priorityfield
sourcemethodRegisters a named poll source with a poll order and optional blocking waiter.
pollmethodPolls registered sources and returns the amount of progress reported.
suspendfieldSubscribes once, then waits for one typed result through the active handler.
installmethodInstalls a handler and returns affine restoration state.
createfieldCreates a coroutine preserving the active suspension context and result pack.
handledmethodReports whether an installed handler owns the current suspension context.
canSuspendmethodReports whether this execution context can perform a suspension.

priorityfield#

priority: integer?
@readonly

sourcemethod#

source: function(
    name: string,
    order: integer,
    poll: function(): integer,
    wait: (function(integer): integer)?,
    active: (function(Source): boolean)?
): Source
@readonly

Registers a named poll source with a poll order and optional blocking waiter. The optional active predicate controls whether the source can make progress.

Arguments
NameTypeDescription
namestring
orderinteger
pollfunction(): integer
wait(function(integer): integer)?
active(function(Source): boolean)?
Returns
TypeDescription
Source

pollmethod#

poll: function(): integer
@readonly

Polls registered sources and returns the amount of progress reported.

Returns
TypeDescription
integer

suspendfield#

suspend: Suspend
@readonly

Subscribes once, then waits for one typed result through the active handler.

installmethod#

install: function(handler: Handler, transparent: boolean?): affine(Installed)
@readonly

Installs a handler and returns affine restoration state.

Arguments
NameTypeDescription
handlerHandler
transparentboolean?
Returns
TypeDescription
affine(Installed)

createfield#

@readonly

Creates a coroutine preserving the active suspension context and result pack.

handledmethod#

handled: function(): boolean
@readonly

Reports whether an installed handler owns the current suspension context.

Returns
TypeDescription
boolean

canSuspendmethod#

canSuspend: function(): boolean
@readonly

Reports whether this execution context can perform a suspension.

Returns
TypeDescription
boolean

Sourcerecord#

record Source ...

Readiness registration shared with callers and handlers. release must be idempotent and non-suspending; provider state tracks its lifetime.

Members

NameKindDescription
releasemethodUnregisters this source without suspending; repeated calls are harmless.
namefieldDiagnostic identity of the readiness source.
orderfieldWhere in a poll pass this source runs; smaller orders are polled first.
waitfieldOptional bounded blocking waiter receiving milliseconds and returning progress.
activefieldOptional predicate deciding whether the source has outstanding work.

releasemethod#

release: @nosuspend function(self: Source): nil

Unregisters this source without suspending; repeated calls are harmless. The provider supplies it with the registration.

Arguments
NameTypeDescription
selfSource
Returns
TypeDescription
nil

namefield#

name: string

Diagnostic identity of the readiness source.

orderfield#

order: integer

Where in a poll pass this source runs; smaller orders are polled first.

waitfield#

wait: (function(integer): integer)?

Optional bounded blocking waiter receiving milliseconds and returning progress.

activefield#

active: (function(source: Source): boolean)?

Optional predicate deciding whether the source has outstanding work.

Suspendtype#

type Suspend = function<T>(operation: string, subscribe: function(function(T), Context): (function()?)): T

Typed 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

NameKindDescription
readymethodReports whether the subscription has settled.
onResumemethodRegisters a wake callback for the waiting scheduler.
operationfieldDiagnostic operation name supplied to suspend.

readymethod#

ready: function(self: Waiting): boolean

Reports whether the subscription has settled.

Arguments
NameTypeDescription
selfWaiting
Returns
TypeDescription
boolean

onResumemethod#

onResume: function(self: Waiting, wake: function(): nil): nil

Registers a wake callback for the waiting scheduler.

Arguments
NameTypeDescription
selfWaiting
wakefunction(): nil
Returns
TypeDescription
nil

operationfield#

operation: string

Diagnostic operation name supplied to suspend.