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

docs: ClientBootstrap reuse is not important but permissible on the same thread/EL #2520

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions Sources/NIOPosix/Bootstrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,17 @@ private extension Channel {

/// A `ClientBootstrap` is an easy way to bootstrap a `SocketChannel` when creating network clients.
///
/// Usually you re-use a `ClientBootstrap` once you set it up and called `connect` multiple times on it.
/// This way you ensure that the same `EventLoop`s will be shared across all your connections.
/// You may re-use a `ClientBootstrap` once you set it up and call `connect` multiple times on it.
/// This ensures all connections you create share the same `EventLoop`.
Copy link
Member

Choose a reason for hiding this comment

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

This is not true. We are taking the next EventLoop from the EventLoopGroup in connect.

///
/// Keep in mind that `ClientBoostrap` is not `Sendable`, so you cannot share the same
/// instance across multiple `EventLoop`s or multiple concurrency domains in general.
/// Creating a `ClientBootstrap` is cheap. So instead of arranging synchronization allowing
/// concurrent code to re-use a single `ClientBootstrap` instance across many tasks, it is often
/// easier to create a dedicated instance for each task.
/// multiple threads/`EventLoop`s. Creating a `ClientBootstrap` is cheap so instead of arranging
/// synchronization to re-use a single `ClientBootstrap` instance across threads, it's advisable to
/// create fresh instances.
Comment on lines +708 to +713
Copy link
Member

Choose a reason for hiding this comment

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

This here is somewhat duplicated

///
/// Example:
///
Expand All @@ -719,7 +728,7 @@ private extension Channel {
/// // resolves to both IPv4 and IPv6 addresses, cf. Happy Eyeballs).
/// channel.pipeline.addHandler(MyChannelHandler())
/// }
/// try! bootstrap.connect(host: "example.org", port: 12345).wait()
/// try bootstrap.connect(host: "example.org", port: 12345).wait()
/// /* the Channel is now connected */
/// ```
///
Expand Down