Thoughts on this idea for a new `select!` syntax in crossbeam-channel? select! { recv(r, msg) => {} // `msg` is of type `Result<T, RecvError>` send(s, msg) => {} default(Duration::from_secs(1)) => {} } The Go equivalent is in the next tweet.
select {
case msg, ok := <-r:
case s <- msg:
case <-time.After(1 * time.Second):
}
Also, do you think this code in Rust should panic if `s` is closed? I'm asking because that's what would happen in Go.
@burntsushi5 - do you perhaps have an opinion?
-
-
An alternative might be to have two kinds of `recv` cases: select! { recv(r, msg) => {} // `msg` is of type `T`, doesn't fire if `r` is closed recv?(r, msg) => {} // `msg` is of type `Result<T, RecvError>` send(s, msg) => {} // doesn't panic if `s` is closed }
Show this threadThanks. Twitter will use this to make your timeline better. UndoUndo
-
-
-
I don't think I have a strong opinion. One idea I have in my head is that it should be possible for people to use channels without writing `unwrap` everywhere. :-)
-
In that case, what should sending a message into a closed channel do? Channels in Go panic, while the chan crate simply leaks the message. The latter is worse, IMO, since that just silently ignores the error.
- 1 more reply
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.