Skip to content

WriteEventPublishInstance

Publishes a declared Event against the Item or App it belongs to, either for asynchronous processing, for processing after a delay, or for inline handling.

Appending an Event, committing it, running its Listeners, and projecting Metrics are separate steps. publish and delay complete at the append; immediate completes after its Listeners return; none of them wait for Metric projection. Reach an instance through item.events.<key> or current.events.<key> inside a write execution.

TProperties = any

Payload shape declared as the Event’s input.

readonly prn: string

PRN of the Event definition this instance publishes.

cancel(id): Promise<void>

Cancels an Event delayed with delay so its Listeners never run.

string

Identifier returned by delay.

Promise<void>

Resolves with no value once the cancellation is recorded within the current execution.

No information is provided on the state of the delayed Event: cancelling one that has already run, has already been cancelled, or does not exist resolves the same way. The cancellation belongs to the caller’s write execution and rolls back with it if that execution fails.


delay(payload, delay): Promise<string>

Appends the Event for the reactor to process once the delay has elapsed.

TProperties

Values for the Event’s declared input.

DurationLike

How long after the current execution’s time the Event becomes due.

Promise<string>

Resolves with an opaque identifier for the delayed Event, to pass to cancel.

The payload is parsed against the Event’s declared input. The Event is processed no earlier than the delay after the current execution’s time; there is no guarantee how soon after that the reactor picks it up. Until then it is not claimable by the reactor and can be withdrawn with cancel. Once due, its Listeners run once, as for publish. The delayed Event belongs to the caller’s write execution and rolls back with it if that execution fails.

Event processing


immediate(payload): Promise<unknown>

Appends the Event and runs its Listeners inline before returning.

TProperties

Values for the Event’s declared input.

Promise<unknown>

Resolves with no meaningful value once every Listener has returned.

The Event is stored as processed, so the reactor does not process it again. Each Listener declared on the Event runs in the caller’s execution, sharing its transaction, time, and authority; a Listener that itself calls immediate recurses inline. A Listener error propagates to the caller and stops further inline processing. The Event and the Listeners’ writes belong to the caller’s write execution and roll back with it if that execution fails.

when the Event has Listeners and the Item it belongs to cannot be loaded.

Immediate events


publish(payloadOrPayloads): Promise<void>

Appends one Event per payload for the reactor to process after the execution commits.

TProperties | TProperties[]

Values for the Event’s declared input, or an array of them to publish several Events at once.

Promise<void>

Resolves once the Events are appended within the current execution.

Awaiting publish awaits the append only. Each payload is parsed against the Event’s declared input. The Events become visible to the reactor when the write execution commits and roll back with it if the execution fails. The reactor then runs each Event’s Listeners in a new write execution of their own, with the Event as its trigger. Passing an empty array appends nothing.

Publishing from a Mutation

await item.events.approved.publish({});