Skip to content

Closing the stream manually #5

@katywings

Description

@katywings

The README mentions that you obviously have to close the stream manually, if you use the keepalive config. Thing is, the API doesn't seem to provide a way to actually do that 😅 and the controller property is protected 🙈.

My workaround for now:

export type SSE = typeof ServerSentEventGenerator.prototype;
export const closeStream = (stream: SSE) => {
  try {
    ((stream as any).controller as ReadableStreamController<any>).close();
  }
  catch(err) {}
}

(The try/catch exists, because there is no way to check if the stream already is closed and closing it multiple times results in an error. Yet onAbort has the tendency to be called multiple times.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions