rust-lang / futures-rs

Zero-cost asynchronous programming in Rust
https://rust-lang.github.io/futures-rs/
Apache License 2.0
5.29k stars 607 forks source link

Add variant of LocalPool with bound lifetime #2846

Open haroldbruintjes opened 3 months ago

haroldbruintjes commented 3 months ago

This modifies LocalPool to accept a generic lifetime parameter, and renames it to BoundLocalPool parameter, with LocalPool now being an alias for BoundLocalPool<'static>. Associated types (Incoming and LocalSpawner) get the same treatment where applicable. Add additional BoundLocalSpawn and BoundLocalSpawnExt traits that extend the unbound variants with functions spawning bound-lifetime tasks.

The purpose of this is to enable the use of an executor that does not require the futures assigned to it to exist any longer than it does. Existing code should of course still just work as it is.

Somewhat tangentially related, the implementations for the various spawner traits have been consolidated to just require Deref, but that need not be part of the same change and does break compatibility. I left it in as a suggestion, but I suspect that should be reverted :).