Lately, I've been working on several real-world systems using Rust's async
and tokio
. As you can see on the areweasyncyet.rs site, this requires using nightly Rust and the experimental tokio-async-await library. I hope to talk more about these experiences soon!
But today, I want to talk about channel APIs in Rust. A question was raised by @matklad on GitHub:
I've migrated rust-analyzer to crossbeam-channel 0.3, and the thing I've noticed is that every
.send
is followed by.unwrap
. Perhaps we should make this unwrapping behavior the default, and introduce a separatechecked_send
which returns a Result?
BurntSushi followed up on Reddit:
Because the vast majority of uses of
send
are like this:ch.send(foo).unwrap()
. That is, you panic because you generally regard it as a bug if you're still sending values when all receivers have been dropped. Why? Because this is generally a property of the program's organization.
I hesitate to disagree with two such excellent developers, but my experiences with this issue are almost the exact opposite of matklad's and BurntSushi's.