smol-rs / async-broadcast

Async broadcast channels
Apache License 2.0
151 stars 26 forks source link

Allow Sender::set_capacity and Sender::set_overflow to take &self instead of &mut self #30

Closed IGreyGooI closed 2 years ago

IGreyGooI commented 2 years ago

Or is there a reason for both functions to only take exclusive references?

zeenix commented 2 years ago

Sorry for the very late reply but I was on vacation.

That's because you're modifying the channel (or Sender in this case). Since we're using mutex internally, at the moment it's not needed but if we were to change the implementation so that we require exterior mutability (i-e &mut self), we'll have to break the API so it's future proof at least. IMO it also makes it explicitly clear that channel is being modified by the call.

I hope that answers you question.