Skip to content

refactor: update ClientBuilder to return a JoinHandle#21

Merged
jmjoy merged 1 commit intomasterfrom
jmjoy/develop
Apr 18, 2025
Merged

refactor: update ClientBuilder to return a JoinHandle#21
jmjoy merged 1 commit intomasterfrom
jmjoy/develop

Conversation

@jmjoy
Copy link
Owner

@jmjoy jmjoy commented Apr 18, 2025

I refactored it this way to allow EventStream to use SteamExt's cool methods, such as map, filter, etc., while allowing users to manipulate Handles to increase flexibility

@jmjoy jmjoy requested a review from Copilot April 18, 2025 17:46
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the ClientBuilder to return an additional JoinHandle, allowing the EventStream to be used with more flexibility while giving the user control over the background task managing the WebSocket connection.

  • Updated build_client API in tests and common modules to return a JoinHandle.
  • Refactored EventStream in src/lib.rs: removed the automatic task abort on drop and replaced it with a Stream trait implementation.
  • Updated examples and Cargo.toml to accommodate the new dependency and API changes.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/integration.rs Updated the usage of build_client to destructure the extra JoinHandle and explicitly abort the task.
tests/common/mod.rs Updated build_client signature to return a JoinHandle.
src/lib.rs Modified ClientBuilder::build, updated EventStream and removed the Drop impl.
examples/text_to_image.rs Adapted ClientBuilder usage to capture and abort the JoinHandle.
Cargo.toml Added pin-project-lite dependency for the new EventStream implementation.
Comments suppressed due to low confidence (2)

src/lib.rs:238

  • [nitpick] Consider renaming 'stream_handle' to a more consistent name like 'handle' or 'join_handle' to match its usage in other parts of the code, such as in the tests.
Ok((client, stream, stream_handle))

src/lib.rs:514

  • The removal of the Drop implementation for EventStream means that the background task is no longer automatically aborted when the stream is dropped. Ensure that this design change is clearly documented so that users understand they must explicitly call abort on the returned JoinHandle to prevent lingering tasks.
impl Drop for EventStream {

@jmjoy jmjoy merged commit 29be4d1 into master Apr 18, 2025
1 check passed
@jmjoy jmjoy deleted the jmjoy/develop branch April 18, 2025 17:52
@github-actions github-actions bot mentioned this pull request Apr 19, 2025
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.

1 participant