From 8a3f478c386828e0ad3b7617aab46d7043726d71 Mon Sep 17 00:00:00 2001 From: Tangent 128 Date: Wed, 16 Oct 2019 00:16:47 -0400 Subject: [PATCH] Give Throttle a ::new() function for now --- src/fixers.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/fixers.rs b/src/fixers.rs index f134b73..dbbba52 100644 --- a/src/fixers.rs +++ b/src/fixers.rs @@ -99,6 +99,17 @@ pub struct Throttle { sleep: Delay } +impl Throttle { + pub fn new(wrap: S) -> Throttle { + let now = Instant::now(); + Throttle { + stream: wrap, + start_time: now, + sleep: delay(now) + } + } +} + impl + Unpin> Stream for Throttle { type Item = Result; @@ -138,12 +149,7 @@ pub trait ChunkStream where Self : Sized + TryStream { } fn throttle(self) -> Throttle { - let now = Instant::now(); - Throttle { - stream: self, - start_time: now, - sleep: delay(now) - } + Throttle::new(self) } }