Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/openai/lib/EventStream.ts>EventStream

Deno build of the official Typescript library for the OpenAI API.
Extremely Popular
Latest
class EventStream
import { EventStream } from "https://deno.land/x/openai@v4.69.0/lib/EventStream.ts";

Constructors

new
EventStream()

Type Parameters

EventTypes extends BaseEvents

Properties

readonly
aborted: boolean
controller: AbortController
readonly
ended: boolean
readonly
errored: boolean

Methods

protected
_emitFinal(): void
protected
_run(this: EventStream<EventTypes>, executor: () => Promise<any>)
_emit<Event extends keyof BaseEvents>(event: Event, ...args: EventParameters<BaseEvents, Event>): void
_emit<Event extends keyof EventTypes>(event: Event, ...args: EventParameters<EventTypes, Event>): void
done(): Promise<void>
emitted<Event extends keyof EventTypes>(event: Event): Promise<EventParameters<EventTypes, Event> extends [infer Param] ? Param : EventParameters<EventTypes, Event> extends [] ? void : EventParameters<EventTypes, Event>>

This is similar to .once(), but returns a Promise that resolves the next time the event is triggered, instead of calling a listener callback.

off<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this

Removes the specified listener from the listener array for the event. off() will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified event, then off() must be called multiple times to remove each instance.

on<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this

Adds the listener function to the end of the listeners array for the event. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of event and listener will result in the listener being added, and called, multiple times.

once<Event extends keyof EventTypes>(event: Event, listener: EventListener<EventTypes, Event>): this

Adds a one-time listener function for the event. The next time the event is triggered, this listener is removed and then invoked.