3

When dealing with Tokio and futures, the futures passed to the Tokio runtime must have a 'static lifetime most of the time. I understand that because the future might be moved to another thread where it can potentially outlive the place it was defined.

There is a method Runtime::block_on_all which guarantees that the future called will be terminated by the end of the call, it even returns the result of running this future.

In that case, I don't get (except for simplicity of the Tokio code) why the future must be 'static.

Can anyone shed some light on this?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Mildred
  • 463
  • 4
  • 13

1 Answers1

3

Looking a little further, it seems I'm right and they have an issue about it: #431 Drop 'static bound on Runtime::block_on[_all]

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Mildred
  • 463
  • 4
  • 13
  • 2
    It would not be the first Rust API to start conservative, and loosen the requirements over time, so I don't think it's necessary so much as it was *obviously* correct and therefore helped get the release out of the door. – Matthieu M. Aug 31 '18 at 10:46