Skip to content

Commit

Permalink
refactor: use transformstream on backend instead of readablestream
Browse files Browse the repository at this point in the history
  • Loading branch information
xynydev committed Apr 22, 2024
1 parent 59f4531 commit ad92aac
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/lib/ts/misc/logStream.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
export async function createLogStream(
func: (log: (newLogLine: string) => void) => void
): Promise<Response> {
const logStream = new ReadableStream({
async start(logStream) {
await func((newLogLine: string) => {
logStream.enqueue(newLogLine + "\n");
});
}
const { readable, writable } = new TransformStream();
const writer = writable.getWriter();

func((newLogLine: string) => {
writer.write(new TextEncoder().encode(newLogLine + "\n"));
});

return new Response(logStream, {
return new Response(readable, {
headers: {
"Content-Type": "text/event-stream",
Connection: "keep-alive",
Expand Down

0 comments on commit ad92aac

Please sign in to comment.