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
9 changes: 7 additions & 2 deletions Sources/NIOPosix/Bootstrap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,14 @@ 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.
/// You may re-use a `ClientBootstrap` once you set it up and called `connect` multiple times on it.
weissi marked this conversation as resolved.
Show resolved Hide resolved
/// This way you ensure that the same `EventLoop`s will be shared across all your connections.
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
weissi marked this conversation as resolved.
Show resolved Hide resolved
/// 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.
///
/// Example:
///
/// ```swift
Expand All @@ -731,7 +736,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