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 Jun 6, 2024
1 parent d56c100 commit 7ed8fcc
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 @@ -2,6 +2,55 @@ use tokio::sync::mpsc::{channel, Sender};

use crate::component_definitions::ComponentRequestAndResponseSender;

/// 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.
#[derive(Clone)]
pub struct ComponentClient<Request, Response>
where
Expand Down

0 comments on commit 7ed8fcc

Please sign in to comment.