Skip to content

Commit

Permalink
book: Use bounded channels instead of unbounded
Browse files Browse the repository at this point in the history
They should be enough in most situations.
  • Loading branch information
Hofer-Julian committed Oct 22, 2023
1 parent 3641400 commit 34f2f00
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion book/listings/main_event_loop/3/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion book/listings/main_event_loop/4/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 34f2f00

Please sign in to comment.