Skip to content

Class: EventsResult ​

A stream of events: Server-Sent Events for the HTTP adapters, each event's data written as a line by the CLI adapter. Build it with Result.events().

The producer runs after the action returned, once the request's container is destroyed: it must only use objects living longer than the request (the components), not the controller's request-scoped dependencies.

Example ​

typescript
import {Controller, Result, type EventsResult} from 'lakutata/com/entrypoint'
import {GET} from 'lakutata/decorator/ctrl'

class ClockController extends Controller {
    //The time every second until the client leaves
    @GET('/clock')
    public async clock(): Promise<EventsResult> {
        return Result.events(async (send, signal): Promise<void> => {
            while (!signal.aborted) {
                send({now: new Date().toISOString()}, 'tick')
                await new Promise((resolve): unknown => setTimeout(resolve, 1000))
            }
        })
    }
}

Extends ​

Constructors ​

Constructor ​

new EventsResult(producer): EventsResult

Create an event stream result.

Parameters ​

producer ​

EventsProducer

Produces the events.

Returns ​

EventsResult

Overrides ​

ActionResult.constructor

Properties ​

producer ​

readonly producer: EventsProducer

Accessors ​

data ​

Get Signature ​

get data(): unknown

Always undefined: an event stream has no data of its own.

Returns ​

unknown

Overrides ​

ActionResult.data

Released under the MIT License.