-
Notifications
You must be signed in to change notification settings - Fork 30
Dropping receivers disconnects the channel #106
Conversation
This is awesome!!! I'll review once you remove the wip notice. |
@arthurprs The PR is in a usable state so you can already try it out. The only thing that still needs work is documentation (don't read it, it makes no sense at the moment :)). @cramertj @aturon Can I ask you for an opinion regarding select! {
recv(receiver) -> res => {
// `res` is of type `Result<T, RecvError>`.
// Note that the `recv` operation might return an error.
println!("recv completed with {:?}", res);
}
send(sender, message) -> res => {
// `res` is of type `Result<(), SendError<T>>`.
// Note that the `send` operation might return an error.
//
// In particular, this case can fire even if the channel is closed and
// the message isn't really sent! In that case, the message is given
// back as the `Err` case.
println!("send completed with {:?}", res);
}
default => {
// This case is optional.
// You can also write `default() =>`.
//
// It's even possible to specify a timeout of type `Duration`
// with `default(timeout) =>`.
println!("all operations would block");
}
} The idea behind An alternative syntax might be On the other hand, Do you agree with these syntactic choices? |
Two things, in my case:
Does the macro allow actual pattern matching in the select! {
recv(my_receiver) -> Ok(value) => { ... }
recv(my_receiver) -> Err(error) => { ... }
...
} as an alternative to doing a |
The thing that goes after In your example, the compiler would complain about non-exhaustive pattern matching (for the same reason it would complain about The way to pattern-match on the result in select! {
recv(my_receiver) -> res => match res {
Ok(value) => { ... }
Err(error) => { ... }
}
...
} Writing |
@arthurprs Ok, the documentation has been updated. I'll let this PR sit for a few days and then merge it and publish a new version. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm very happy about this, I couldn't find anything weird but this is my first look at the internals.
Something that came to mind was to (eventually) change some internal asserts and unwraps into debug_assert and debug_unwrap.
@arthurprs Thanks for taking a look at the code! I'm very happy about it, too. This PR also simplifies the selection mechanism so now the
Yes, there are a few places where we could do that. If it doesn't affect performance, I often choose |
NOTE: This PR is a work in progress.
The main change is: Dropping all receivers closes the channel.
See #61 for the rationale.
Other notable changes in this PR:
send
inselect!
is nowsend(sender, msg) -> res => body
.recv
inselect!
is nowrecv(receiver) -> res => body
.default
case inselect!
.Select
struct is revamped.Sender
/Receiver
interface is now similar to what we had in version 0.1.never
channel that never delivers messages.Closes #61
Closes #99
Closes #55