Why futures `select!` takes async action as mutable?

Why futures select! takes async action as mutable?

I have a following snippet:

let running_server = runtime.spawn(server_future).fuse();
let async_tasks = async { select! {
        res = running_server => match res { ... },

and it doesn't compile with an error:

error[E0596]: cannot borrow `running_server` as mutable, as it is not declared as mutable
    |
    = note: this error originates in the macro `$crate::select_internal` which comes from the expansion of the macro `select` (in Nightly builds, run with -Z macro-backtrace for more info)

In my (nightly) rust version the above mentioned flag is not supported.

The select! macro has to be able to poll the future, which requires mutable access to it.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.