Skip to content

Commit

Permalink
docs: add documentation for component client
Browse files Browse the repository at this point in the history
commit-id:d3030c87
  • Loading branch information
Itay-Tsabary-Starkware committed Jul 22, 2024
1 parent c9f77e7 commit 6659308
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions crates/mempool_infra/src/component_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,55 @@ use crate::component_definitions::{
ComponentRequestAndResponseSender, ServerError, APPLICATION_OCTET_STREAM,
};

/// The `ComponentClient` struct is a generic client for sending component requests and receiving
/// responses asynchronously.
///
/// # Type Parameters
/// - `Request`: The type of the request. This type must implement both `Send` and `Sync` traits.
/// - `Response`: The type of the response. This type must implement both `Send` and `Sync` traits.
///
/// # Fields
/// - `tx`: An asynchronous sender channel for transmitting
/// `ComponentRequestAndResponseSender<Request, Response>` messages.
///
/// # Example
/// ```rust
/// // Example usage of the ComponentClient
/// use tokio::sync::mpsc::Sender;
///
/// use crate::starknet_mempool_infra::component_client::ComponentClient;
/// use crate::starknet_mempool_infra::component_definitions::ComponentRequestAndResponseSender;
///
/// // Define your request and response types
/// struct MyRequest {
/// pub content: String,
/// }
///
/// struct MyResponse {
/// content: String,
/// }
///
/// #[tokio::main]
/// async fn main() {
/// // Create a channel for sending requests and receiving responses
/// let (tx, _rx) = tokio::sync::mpsc::channel::<
/// ComponentRequestAndResponseSender<MyRequest, MyResponse>,
/// >(100);
///
/// // Instantiate the client.
/// let client = ComponentClient::new(tx);
///
/// // Instantiate a request.
/// let request = MyRequest { content: "Hello, world!".to_string() };
///
/// // Send the request; typically, the client should await for a response.
/// client.send(request);
/// }
/// ```
///
/// # Notes
/// - The `ComponentClient` struct is designed to work in an asynchronous environment, utilizing
/// Tokio's async runtime and channels.
pub struct ComponentClient<Request, Response>
where
Request: Send + Sync,
Expand Down

0 comments on commit 6659308

Please sign in to comment.