Skip to content

Commit 0457065

Browse files
authored
Do not use Instant::now when zero reset streams are configured. (#537)
This allows to use `h2` on wasm platforms which lack an `Instant::now` implementation by setting the number of streams to 0 with: `h2::client::Builder::max_concurrent_reset_streams`.
1 parent 361de98 commit 0457065

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/proto/streams/recv.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -866,13 +866,15 @@ impl Recv {
866866
}
867867

868868
pub fn clear_expired_reset_streams(&mut self, store: &mut Store, counts: &mut Counts) {
869-
let now = Instant::now();
870-
let reset_duration = self.reset_duration;
871-
while let Some(stream) = self.pending_reset_expired.pop_if(store, |stream| {
872-
let reset_at = stream.reset_at.expect("reset_at must be set if in queue");
873-
now - reset_at > reset_duration
874-
}) {
875-
counts.transition_after(stream, true);
869+
if !self.pending_reset_expired.is_empty() {
870+
let now = Instant::now();
871+
let reset_duration = self.reset_duration;
872+
while let Some(stream) = self.pending_reset_expired.pop_if(store, |stream| {
873+
let reset_at = stream.reset_at.expect("reset_at must be set if in queue");
874+
now - reset_at > reset_duration
875+
}) {
876+
counts.transition_after(stream, true);
877+
}
876878
}
877879
}
878880

src/proto/streams/store.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ where
304304
None
305305
}
306306

307+
pub fn is_empty(&self) -> bool {
308+
self.indices.is_none()
309+
}
310+
307311
pub fn pop_if<'a, R, F>(&mut self, store: &'a mut R, f: F) -> Option<store::Ptr<'a>>
308312
where
309313
R: Resolve,

0 commit comments

Comments
 (0)