From 34f2f00bf1710229388c016e69a0dddddd6b11f1 Mon Sep 17 00:00:00 2001 From: Julian Hofer Date: Sun, 22 Oct 2023 14:39:50 +0200 Subject: [PATCH] book: Use bounded channels instead of unbounded They should be enough in most situations. --- book/listings/main_event_loop/3/main.rs | 3 ++- book/listings/main_event_loop/4/main.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/book/listings/main_event_loop/3/main.rs b/book/listings/main_event_loop/3/main.rs index 8a9944e285f7..4d5abca139a3 100644 --- a/book/listings/main_event_loop/3/main.rs +++ b/book/listings/main_event_loop/3/main.rs @@ -29,7 +29,8 @@ fn build_ui(app: &Application) { .build(); // ANCHOR: callback - let (sender, receiver) = async_channel::unbounded(); + // Create channel that can hold at most 1 message at a time + let (sender, receiver) = async_channel::bounded(1); // Connect to "clicked" signal of `button` button.connect_clicked(move |_| { let sender = sender.clone(); diff --git a/book/listings/main_event_loop/4/main.rs b/book/listings/main_event_loop/4/main.rs index 6c8fc44e3b1d..4a992dbd1336 100644 --- a/book/listings/main_event_loop/4/main.rs +++ b/book/listings/main_event_loop/4/main.rs @@ -26,7 +26,8 @@ fn build_ui(app: &Application) { .build(); // ANCHOR: callback - let (sender, receiver) = async_channel::unbounded(); + // Create channel that can hold at most 1 message at a time + let (sender, receiver) = async_channel::bounded(1); // Connect to "clicked" signal of `button` button.connect_clicked(move |_| { let main_context = MainContext::default();