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 10 commits into
base: main
Choose a base branch
from
15 changes: 12 additions & 3 deletions Sources/NIOPosix/Bootstrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -778,8 +778,17 @@ 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`.
weissi marked this conversation as resolved.
Show resolved Hide resolved
///
/// 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.
weissi marked this conversation as resolved.
Show resolved Hide resolved
///
/// Example:
///
Expand All @@ -797,7 +806,7 @@ 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
Loading