Skip to content
This repository has been archived by the owner on Nov 5, 2018. It is now read-only.

Idea: improved Select struct #99

Closed
ghost opened this issue Sep 25, 2018 · 0 comments · Fixed by #106
Closed

Idea: improved Select struct #99

ghost opened this issue Sep 25, 2018 · 0 comments · Fixed by #106

Comments

@ghost
Copy link

ghost commented Sep 25, 2018

The current Select stores closures for firing cases. This is slow and interacts poorly with the borrow checker.

I think we could have interface like this:

let mut sel: Select<'_> = Select::new();
let id1 = sel.add_send(&s);
let id2 = sel.add_recv(&r);
let id = sel.wait();

if id == id1 {
    let res = sel.finish_send(s, msg);
} else if id == id2 {
    let res = sel.finish_recv(r);
}

Functions finish_send and finish_recv would panic if wrong sender or receiver is passed. Select stores a Token internally that is used for the finishing function call.

Also, we could probably support reusing sel in multiple selections.

As further simplification, we could also:

  • Remove the codegen in select! and instead "compile" the macro invocation down to Select.
  • Remove support for sending into iterators of receivers/senders in select! because the syntax odd, it is a niche use case, and can be done using Select anyway.
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging a pull request may close this issue.

0 participants