Skip to content

Commit

Permalink
simplify channels cleanup logic
Browse files Browse the repository at this point in the history
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
  • Loading branch information
Keruspe committed Jul 14, 2023
1 parent f3fdbc4 commit abe95d9
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ impl Channels {

pub(crate) fn set_connection_closed(&self, error: Error) {
self.connection_status.set_state(ConnectionState::Closed);
for (id, channel) in self.inner.lock().take_channels().drain() {
self.frames.clear_expected_replies(id, error.clone());
for (id, channel) in self.inner.lock().channels.iter() {
self.frames.clear_expected_replies(*id, error.clone());
channel.set_closed(error.clone());
}
}
Expand All @@ -140,8 +140,8 @@ impl Channels {
self.connection_status.set_state(ConnectionState::Error);
self.frames.drop_pending(error.clone());
self.error_handler.on_error(error.clone());
for (id, channel) in self.inner.lock().take_channels().drain() {
self.frames.clear_expected_replies(id, error.clone());
for (id, channel) in self.inner.lock().channels.iter() {
self.frames.clear_expected_replies(*id, error.clone());
channel.set_connection_error(error.clone());
}
}
Expand Down Expand Up @@ -369,13 +369,4 @@ impl Inner {
}
Err(Error::ChannelsLimitReached)
}

fn take_channels(&mut self) -> HashMap<ChannelId, Channel> {
let channel0 = self.channels.get(&0).cloned();
let channels = std::mem::take(&mut self.channels);
if let Some(channel0) = channel0 {
self.channels.insert(0, channel0);
}
channels
}
}

0 comments on commit abe95d9

Please sign in to comment.