Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The generator's response is actually inconsistent #755

Open
HK-SHAO opened this issue Jul 25, 2024 · 3 comments
Open

The generator's response is actually inconsistent #755

HK-SHAO opened this issue Jul 25, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@HK-SHAO
Copy link

HK-SHAO commented Jul 25, 2024

What version of Elysia.JS is running?

1.1.4

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

server.ts:

import Elysia from "elysia";

export const app = new Elysia().post("/stream", async function* () {
  yield {hello: "world"};
  yield {hello: "world"};
  yield {hello: "world"};
});

app.listen(2345);

client.ts:

import { treaty } from "@elysiajs/eden";
import type { app } from ".";

const client = treaty<typeof app>("http://localhost:2345");

const { data, error } = await client.stream.post();
if (!data) throw error;

for await (let item of data) {
  console.log(item, typeof item);
}

What is the expected behavior?

% bun run client.ts
{
  hello: "world",
} object
{
  hello: "world",
} object
{
  hello: "world",
} object

What do you see instead?

% bun run client.ts
{"hello":"world"}{"hello":"world"} string
{
  hello: "world",
} object

Additional information

Sometimes numeric responses are merged together into a single number, and sometimes json obejct responses are merged into a single string. The same goes for non-asynchronous.

@HK-SHAO HK-SHAO added the bug Something isn't working label Jul 25, 2024
@HK-SHAO HK-SHAO changed the title The async generator's response is actually inconsistent The generator's response is actually inconsistent Jul 25, 2024
@remorses
Copy link

will be fixed by #743 and elysiajs/eden#114

@HK-SHAO
Copy link
Author

HK-SHAO commented Aug 1, 2024

will be fixed by #743 and elysiajs/eden#114

@remorses A similar problem occurs in response to new ReadableStream(), which I solved by adding an await delay(0) after each controller.enqueue()

@HK-SHAO
Copy link
Author

HK-SHAO commented Sep 2, 2024

@SaltyAom When I sleep before each yield, it prevents objects from sticking into strings, do you think this is a bug in Bun?

import Elysia from "elysia";

export const server = new Elysia().post("/stream", async function* () {
  yield { hello: "world" };
  await Bun.sleep(0);
  yield { hello: "world" };
  await Bun.sleep(0);
  yield { hello: "world" };
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants