Skip to content

Refactor: Pass shutdown receiver by value instead of mutable reference #37

@coderabbitai

Description

@coderabbitai

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:

  1. Update worker_task function signature to take mut shutdown_rx: broadcast::Receiver<()> instead of shutdown_rx: &mut broadcast::Receiver<()>
  2. Update spawn calls to pass receiver by value instead of mutable reference
  3. 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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions