Clean up ChannelState ready_to_expire

This commit is contained in:
Yuan Lyu 2022-02-06 15:25:52 -05:00
parent f6f732a478
commit 3552a49652
1 changed files with 9 additions and 10 deletions

View File

@ -94,7 +94,7 @@ impl<C: AbstractChannel> ChannelState<C> {
}
}
/// Return true if a channel is ready to expire `now`.
/// Return true if a channel is ready to expire.
/// Update `expire_after` if a smaller duration than
/// the given value is required to expire this channel.
fn ready_to_expire(&self, expire_after: &mut Duration) -> bool {
@ -103,19 +103,18 @@ impl<C: AbstractChannel> ChannelState<C> {
if let Some(unused_duration) = unused_duration {
let max_unused_duration = ent.max_unused_duration;
if unused_duration < max_unused_duration {
*expire_after =
std::cmp::min(*expire_after, max_unused_duration - unused_duration);
true
} else {
if let Some(remaining) = max_unused_duration.checked_sub(unused_duration) {
*expire_after = std::cmp::min(*expire_after, remaining);
false
} else {
true
}
} else {
// still in use
true
false
}
} else {
true
false
}
}
}
@ -224,7 +223,7 @@ impl<C: AbstractChannel> ChannelMap<C> {
self.channels
.lock()
.expect("Poisoned lock")
.retain(|_id, chan| chan.ready_to_expire(&mut ret));
.retain(|_id, chan| !chan.ready_to_expire(&mut ret));
ret
}
}