-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
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}`
);
dinirichard
Metadata
Metadata
Assignees
Labels
No labels