How to select channels?

I checked the mpsc::Select which is deprecated and nightly only. What is the rust way of handling multiple signals if there's no select?


You should use crossbeam instead: GitHub - crossbeam-rs/crossbeam: Tools for concurrent programming in Rust


does this mean rust's own std channels are all together deprecated ?

Select for mpsc won't happen, so there is a proposal to replace stdlib's implementation with crossbeam's (and/or deprecate):

That makes sense because i cant just imagine using channels without select

It's interesting how different people's usages are. I've used mpsc in at least three different projects, and never needed select.

How did you handle kill signals or timeouts ?

For simple utilities I use ctrlc crate and timeouts built into HTTP clients. For bigger ones Actix has handling of these built-in (plus Futures composed with timers).

i meant internally how did you handle those. For instance you have something that is listening to a channel you may need to tell it to stop and gracefully return

If the sending side is destroyed, the receiver stops listening automatically.

It's also usual to send enum Message { Do(Stuff), Exit }.

im coming from golang background in go often you have goroutines waiting for data from one channel or context.Done and you can possibly have more channels for different sorts of things and you use select for this
I guess this is not a rusty use case but still its a valid one :slight_smile:

@kornel actually yes the enum makes sense i always forget how powerfull rust enums are
@kornel here i have a small example of go way :slight_smile: so in rust this could be done in a typesafe way using enums :slight_smile: +1 for rust then :smiley:

Yeah, channels do a lot of work in Go. In Rust that's more specific, e.g. you'd use Rayon's parallel iterators or scopes to process multiple things in parallel and wait for them. Some waiting can be arranged around mutexes, etc.