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.
Remarks
Section titled “Remarks”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.
- Handle events
- Event publishing
- EventBuilder for declaring an Event
Type Parameters
Section titled “Type Parameters”TProperties
Section titled “TProperties”TProperties = any
Payload shape declared as the Event’s input.
Properties
Section titled “Properties”
readonlyprn:string
PRN of the Event definition this instance publishes.
Methods
Section titled “Methods”cancel()
Section titled “cancel()”cancel(
id):Promise<void>
Cancels an Event delayed with delay so its Listeners never run.
Parameters
Section titled “Parameters”string
Identifier returned by delay.
Returns
Section titled “Returns”Promise<void>
Resolves with no value once the cancellation is recorded within the current execution.
Remarks
Section titled “Remarks”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()
Section titled “delay()”delay(
payload,delay):Promise<string>
Appends the Event for the reactor to process once the delay has elapsed.
Parameters
Section titled “Parameters”payload
Section titled “payload”TProperties
Values for the Event’s declared input.
DurationLike
How long after the current execution’s time the Event becomes due.
Returns
Section titled “Returns”Promise<string>
Resolves with an opaque identifier for the delayed Event, to pass to cancel.
Remarks
Section titled “Remarks”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.
immediate()
Section titled “immediate()”immediate(
payload):Promise<unknown>
Appends the Event and runs its Listeners inline before returning.
Parameters
Section titled “Parameters”payload
Section titled “payload”TProperties
Values for the Event’s declared input.
Returns
Section titled “Returns”Promise<unknown>
Resolves with no meaningful value once every Listener has returned.
Remarks
Section titled “Remarks”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.
Throws
Section titled “Throws”when the Event has Listeners and the Item it belongs to cannot be loaded.
publish()
Section titled “publish()”publish(
payloadOrPayloads):Promise<void>
Appends one Event per payload for the reactor to process after the execution commits.
Parameters
Section titled “Parameters”payloadOrPayloads
Section titled “payloadOrPayloads”TProperties | TProperties[]
Values for the Event’s declared input, or an array of them to publish several Events at once.
Returns
Section titled “Returns”Promise<void>
Resolves once the Events are appended within the current execution.
Remarks
Section titled “Remarks”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.
Example
Section titled “Example”Publishing from a Mutation
await item.events.approved.publish({});
