Skip to content

Should Stream be really deprecated? #14

@wladpaiva

Description

@wladpaiva

Nothing wrong with the generator function but doesn't work on every possible case.

If you are sending data from a event emitter like this you won't be able to use the generator

import { Elysia } from "elysia";
import { Stream } from "@elysiajs/stream";
import { EventEmitter } from "node:events";

/**
 * The event emitter for the whole application.
 */
export let emitter = new EventEmitter<{
  x: [];
}>();

const app = new Elysia()
  .get(
    "/",
    () =>
      new Stream(async (stream) => {
        console.log("Started streaming");

        emitter.on("x", () => {
          stream.send(new Date().toISOString());
        });
      })
  )
  .listen(3000);

setInterval(() => {
  console.info("Emitting transaction status changed");
  emitter.emit("x");
}, 30_000);

console.log(
  `🦊 Elysia is running at http://${app.server?.hostname}:${app.server?.port}`
);

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