Refactor SSE callback to handle async operations #6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request includes changes to enhance the Server-Sent Events (SSE) handler in
src/server/sse-server.ts
. The updates focus on improving the flexibility and functionality of the SSE callback and adding guidance for handling long-running operations.Enhancements to SSE handler:
src/server/sse-server.ts
: Updated theSSECallback
type to allow the callback to return a promise that resolves to a cleanup function or a function that returns a promise.src/server/sse-server.ts
: Added a hint in the documentation to avoid awaiting long-running operations directly in the callback to prevent blocking the initial response.src/server/sse-server.ts
: Modified thestart
method increateSSEHandler
to be asynchronous, allowing for better handling of asynchronous operations within the callback.src/server/sse-server.ts
: Updated the invocation of thecallback
increateSSEHandler
to await its result, ensuring proper handling of asynchronous callbacks.