Skip to content
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

macros: select! not evaluate async expression if precondition fails #6555

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kezhuw
Copy link
Contributor

@kezhuw kezhuw commented May 13, 2024

Motivation

This permits following code without a panic.

let mut value = Some(5);
loop {
  select! {
      _ = ready(value.take().unwrap()), if value.is_some() => {},
      else => break,
  };
}

Currently, <async expression> in select! is evaluated regardless of its precondition. I, personally, think usually async expression is guarded for a reason that it is probably not in a valid state. There are might be cases the evaluation of async expression is pure with side effect, but it is not always. So, I think it might be better to guard evaluation by its precondition.

Solution

Fill futures tuple with None initially and fill them up only if precondition succeed.

Question

I have not polished the code. Before that, I want to make up an agreement.

Does this sound and do we want this ? This is most likely a breaking change. No sure whether we are depending on this subtlety.

Origins

This comes from my experiment in async_select::select.

This permits following code without a panic.

```
let mut value = Some(5);
loop {
  select! {
      _ = ready(value.take().unwrap()), if value.is_some() => {},
  };
}
```
@kezhuw
Copy link
Contributor Author

kezhuw commented May 13, 2024

Another behavior changed is that it drop future eagerly after Poll::Ready. But I think this is optional and pure implementation detail.

@Darksonn
Copy link
Contributor

This is probably what we would want, but I'm concerned about breaking changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants