Skip to content

Commit c72f5d8

Browse files
committed
feedback: add note one time spent reading vs writing code
1 parent 3b2f5b1 commit c72f5d8

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

content/concurrency-patterns.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ frame #1: channel-per-writer`tokio::runtime::task::core::Core::poll at core.rs:3
779779

780780
This means it's reasonable to expect the value of the variable to come from some local function call, as there's nothing up stack we can look at in our own code. Let's trace back where `Message::Send(...)` comes from, then: first we can see there's a match with `msg`, so we need to find `msg`, which is defined a few lines above from `let Some(msg) = rx.next().await`. From just the line above`rx` is a combination of `write_error_rx` and `reader_rx`, `write_reader_rx` is a channel we created locally, so we can trace down its corresponding `Sender`, but `reader_rx` comes from the caller of `central_dispatcher` which we can't find in the backtrace!
781781

782-
This is potentially a problem with any callback, but it's worse with channels. Even if you manage to track down where the channel is created, it doesn't tell you which the source of the received values is; for that you need to find the corresponding `Sender`. But as the `Sender` is cloneable, you could find it in multiple places. And more than one of those places could potentially send the same variant, making it impossible to correlate the function that sent the values with the value received in a normal debugger. This can make programs very difficult both to understand and to debug.
782+
This is potentially a problem with any callback, but it's worse with channels. Even if you manage to track down where the channel is created, it doesn't tell you which the source of the received values is; for that you need to find the corresponding `Sender`. But as the `Sender` is cloneable, you could find it in multiple places. And more than one of those places could potentially send the same variant, making it impossible to correlate the function that sent the values with the value received in a normal debugger. This can make programs very difficult both to understand and to debug; considering that for most of us we spend more time reading than writing code, this is a high price to pay.
783783

784784
Contrast this with the `Mutex` version of `handle_connection`:
785785

0 commit comments

Comments
 (0)