-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wait on a set of operations without committing to any #245
Conversation
cc @tecywiz121 @matklad You might like these new methods for dynamic selection, too! |
To illustrate, here's how you can use this API: let mut sel = Select::new();
sel.recv(&r1); // has index 0
sel.recv(&r2); // has index 1
sel.send(&s3); // has index 2
match sel.ready_timeout(Duration::from_secs(1)) {
Err(_) => println!("timed out"),
Ok(0) => println!("r1 is ready"),
Ok(1) => println!("r2 is ready"),
Ok(2) => println!("s3 is ready"),
Ok(_) => unreachable!(),
} |
Oooh, that looks very promising! I'll take a closer look later today, but I'd be very excited to use this in session-types! |
With regards to the naming, I think the current schema is pretty good 👍 |
Thanks to @stjepang and crossbeam-rs/crossbeam#245 It looks like it works. Now to add the more complicated chan_select stuff.
Thanks to @stjepang and crossbeam-rs/crossbeam#245 It looks like it works. Now to add the more complicated chan_select stuff.
A sort of related question: do you think |
I think @Munksgaard already did the best possible testing of: actually using it 😛 Looks good, it'll definitely simplify the session-types select implementation.
For our use case, I don't think so. |
Thanks for your feedback, @Munksgaard and @laumann! I'm happy to hear this feature proved to be useful! :) Let's merge and I'll publish a new version soon. bors r+ |
245: Wait on a set of operations without committing to any r=stjepang a=stjepang This PR adds methods `Select::{try_ready,ready,ready_timeout}`, which wait on a set of operations until any one of them becomes ready. However, after that we're not obliged to "complete" the operation. cc @Munksgaard @laumann This would help in resolving Munksgaard/session-types#45 Closes #222. If anyone thinks we should name these methods differently, speak up! :) 249: Add additional is_* methods to error types r=stjepang a=stjepang Add methods like `is_disconnected()`, `is_full()`, and `is_empty()` to error types returned by channel operations. Co-authored-by: Stjepan Glavina <stjepang@gmail.com>
Build succeeded |
I'm a little late to the party, but how about having each That way you don't have to guess at the index, and you get some type safety? |
@tecywiz121 That makes sense. I'll consider this change for the final set of breaking changes before version 1.0 early next year. Which one of these you prefer?
I kind of like that |
Yeah, I don't really mind using plain integers either. Both options are appealing. The first one is nice because the library takes care of assigning tokens and it should make bookkeeping easier. The second option allows an application to define all their tokens up front statically, and not have to wait to use them. I guess my preference depends on the distance between where |
This PR adds methods
Select::{try_ready,ready,ready_timeout}
, which wait on a set of operations until any one of them becomes ready. However, after that we're not obliged to "complete" the operation.cc @Munksgaard @laumann This would help in resolving Munksgaard/session-types#45
Closes #222.
If anyone thinks we should name these methods differently, speak up! :)