From fd8bed689dfe6aa419c0b314cecc8f1fb522df0b Mon Sep 17 00:00:00 2001 From: Titouan Rigoudy Date: Sun, 14 Nov 2021 09:53:50 +0100 Subject: [PATCH] Define a constant for the channel buffer size. --- client/src/main.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/client/src/main.rs b/client/src/main.rs index 29129f8..b8e3567 100644 --- a/client/src/main.rs +++ b/client/src/main.rs @@ -25,9 +25,14 @@ use config::{Config, TomlConfig}; use context::{ContextBundle, ContextOptions}; use dispatcher::Dispatcher; +// Size of various channels defined below. +const CHANNEL_BUFFER_SIZE: usize = 100; + fn old_main(config: Config) { - let (request_tx, _request_rx) = crossbeam_channel::bounded(100); - let (_response_tx, response_rx) = crossbeam_channel::bounded(100); + let (request_tx, _request_rx) = + crossbeam_channel::bounded(CHANNEL_BUFFER_SIZE); + let (_response_tx, response_rx) = + crossbeam_channel::bounded(CHANNEL_BUFFER_SIZE); let mut client = client::Client::new(request_tx, response_rx, config); @@ -52,8 +57,7 @@ async fn run_client( .context("logging in")?; info!("Login successful."); - // TODO: Define a constant for this, or something. - let (response_tx, mut response_rx) = mpsc::channel(100); + let (response_tx, mut response_rx) = mpsc::channel(CHANNEL_BUFFER_SIZE); let forwarder_task = tokio::spawn(async move { while let Some(response) = response_rx.recv().await { dispatcher_tx @@ -83,8 +87,7 @@ async fn async_main(config: Config) -> anyhow::Result<()> { let bundle = ContextBundle::new(options); - // TODO: Define a constant for this, or something. - let (dispatcher_tx, mut dispatcher_rx) = mpsc::channel(100); + let (dispatcher_tx, mut dispatcher_rx) = mpsc::channel(CHANNEL_BUFFER_SIZE); let mut control_listener = control::Listener::bind(&config.control_listen_address)