Skip to content

Commit fb3ef4d

Browse files
authored
book: Use bounded channels instead of unbounded (#1522)
They should be enough in most situations.
1 parent 3641400 commit fb3ef4d

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

book/listings/main_event_loop/3/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ fn build_ui(app: &Application) {
2929
.build();
3030

3131
// ANCHOR: callback
32-
let (sender, receiver) = async_channel::unbounded();
32+
// Create channel that can hold at most 1 message at a time
33+
let (sender, receiver) = async_channel::bounded(1);
3334
// Connect to "clicked" signal of `button`
3435
button.connect_clicked(move |_| {
3536
let sender = sender.clone();

book/listings/main_event_loop/4/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ fn build_ui(app: &Application) {
2626
.build();
2727

2828
// ANCHOR: callback
29-
let (sender, receiver) = async_channel::unbounded();
29+
// Create channel that can hold at most 1 message at a time
30+
let (sender, receiver) = async_channel::bounded(1);
3031
// Connect to "clicked" signal of `button`
3132
button.connect_clicked(move |_| {
3233
let main_context = MainContext::default();

0 commit comments

Comments
 (0)