Description
The current implementation passes the shutdown receiver as a mutable reference (&mut shutdown_rx) into async move closures for worker tasks, creating unnecessary lifetime complexity and confusion about ownership.
Affected Code
File: src/server.rs
Lines: 289-299 and 321-333
Current Implementation Issue
Each worker owns its own broadcast::Receiver, but capturing &mut shutdown_rx inside an async move closure creates an unnecessary lifetime dance and misleads readers into thinking the receiver outlives the task.
Suggested Solution
Pass shutdown_rx by value into the closure instead of by mutable reference, so each worker owns its receiver directly.
Changes needed:
- Update
worker_task function signature to take mut shutdown_rx: broadcast::Receiver<()> instead of shutdown_rx: &mut broadcast::Receiver<()>
- Update spawn calls to pass receiver by value instead of mutable reference
- Remove
async move complexity around receiver ownership
Benefits
- Simplifies ownership model
- Removes unnecessary lifetime complexity
- Avoids hidden self-references inside spawned futures
- Makes code more readable and maintainable
References
Requested by: leynos
Description
The current implementation passes the shutdown receiver as a mutable reference (
&mut shutdown_rx) into async move closures for worker tasks, creating unnecessary lifetime complexity and confusion about ownership.Affected Code
File:
src/server.rsLines: 289-299 and 321-333
Current Implementation Issue
Each worker owns its own
broadcast::Receiver, but capturing&mut shutdown_rxinside anasync moveclosure creates an unnecessary lifetime dance and misleads readers into thinking the receiver outlives the task.Suggested Solution
Pass
shutdown_rxby value into the closure instead of by mutable reference, so each worker owns its receiver directly.Changes needed:
worker_taskfunction signature to takemut shutdown_rx: broadcast::Receiver<()>instead ofshutdown_rx: &mut broadcast::Receiver<()>async movecomplexity around receiver ownershipBenefits
References
Requested by: leynos