pub struct ClientBuilder<U> { /* private fields */ }
Expand description
A builder for creating a ComfyUIClient
instance.
This builder helps initialize the client with the provided base URL and sets up a websocket connection to stream events.
Implementations§
Source§impl<U: IntoUrl> ClientBuilder<U>
impl<U: IntoUrl> ClientBuilder<U>
Sourcepub fn new(base_url: U) -> Self
pub fn new(base_url: U) -> Self
Creates a new ClientBuilder
instance.
§Parameters
base_url
: The base URL of the ComfyUI service.
§Returns
A new instance of ClientBuilder
wrapped in a ClientResult
, or an
error if the URL is invalid.
Sourcepub fn channel_bound(self, channel_bound: usize) -> Self
pub fn channel_bound(self, channel_bound: usize) -> Self
Sets the capacity of the internal channel used for event streaming.
This controls how many events can be buffered before backpressure is applied. The default value is 100.
§Parameters
channel_bound
: The maximum number of events the channel can hold.
§Returns
The updated ClientBuilder
instance.
Sourcepub fn reconnect_web_socket(self, reconnect: bool) -> Self
pub fn reconnect_web_socket(self, reconnect: bool) -> Self
Sets whether the websocket should attempt to reconnect automatically when disconnected.
By default, reconnection is enabled (true
).
§Parameters
reconnect
: Whether to attempt reconnection when the WebSocket connection drops unexpectedly.
§Returns
The updated ClientBuilder
instance.
Sourcepub async fn build(self) -> ClientResult<(ComfyUIClient, EventStream)>
pub async fn build(self) -> ClientResult<(ComfyUIClient, EventStream)>
Builds the ComfyUIClient
along with an associated EventStream
and a background task handle.
This method establishes a websocket connection and spawns an asynchronous task to process incoming messages. If reconnection is enabled, the task will automatically attempt to reconnect when the WebSocket connection drops unexpectedly.
§Returns
A tuple containing:
- The
ComfyUIClient
for HTTP API interactions - An
EventStream
for receiving real-time events
The WebSocket connection will be automatically closed when the
EventStream
is dropped, as the background task managing the
connection terminates when the stream is no longer being consumed.
Returns an error if the initial connection cannot be established.
Sourcepub async fn build_only_http(self) -> ClientResult<ComfyUIClient>
pub async fn build_only_http(self) -> ClientResult<ComfyUIClient>
Builds a ComfyUIClient
instance configured for HTTP-only
communication.
This method initializes the client without establishing a websocket connection, enabling you to interact with the ComfyUI service using only HTTP (REST) requests.
§Returns
A ComfyUIClient
instance on success, or an error.