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

chore(sse): refactor sse utils with cursor #4356

Closed
wants to merge 4 commits into from
Closed

Conversation

bojiang
Copy link
Member

@bojiang bojiang commented Dec 22, 2023

What does this PR address?

Fixes #(issue)

Before submitting:

Sorry, something went wrong.

@bojiang bojiang requested a review from a team as a code owner December 22, 2023 09:59
@bojiang bojiang requested review from aarnphm and removed request for a team December 22, 2023 09:59
@bojiang bojiang changed the title chore(sse): refactor sse utils with efficient buffering chore(sse): refactor sse utils with cursor Dec 22, 2023
@bojiang bojiang requested a review from jianshen92 December 22, 2023 10:04
Comment on lines +88 to +92
"\n\n" in chunk
or chunk
and chunk[0] == "\n"
and last_chunk
and last_chunk[-1] == "\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this part needed? Could we always just append the buffer until we see \n\n and then update the cursor?

Copy link
Member Author

@bojiang bojiang Dec 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chunking may happen right in the middle of \n\n and break down it into two chunks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if that happens maybe we just simply wait for the next chunk to arrive?

Copy link
Member Author

@bojiang bojiang Dec 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. You may take a closer look at the process here, or edit as you want and check if the unit test can still pass.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, i understood what you wrote. I think we can just have while '\n\n' in chunks condition, and that will solve two problem at once:

  1. The scenario you mentioned, where its chunked between two \n character, it will simply wait for the next chunk to enter the buffer then we will have the full delimiter again.
  2. Multiple events in the same chunk, it will then yield multiple times before it receives the next chunk into buffer

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
@bojiang bojiang closed this Dec 25, 2023
@bojiang
Copy link
Member Author

bojiang commented Dec 25, 2023

open from another branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants