Give Throttle a ::new() function for now

This commit is contained in:
Tangent 128 2019-10-16 00:16:47 -04:00
parent 49fa0ff7e0
commit 8a3f478c38
1 changed files with 12 additions and 6 deletions

View File

@ -99,6 +99,17 @@ pub struct Throttle<S> {
sleep: Delay
}
impl<S> Throttle<S> {
pub fn new(wrap: S) -> Throttle<S> {
let now = Instant::now();
Throttle {
stream: wrap,
start_time: now,
sleep: delay(now)
}
}
}
impl<S: TryStream<Ok = Chunk, Error = WebmetroError> + Unpin> Stream for Throttle<S>
{
type Item = Result<Chunk, WebmetroError>;
@ -138,12 +149,7 @@ pub trait ChunkStream where Self : Sized + TryStream<Ok = Chunk> {
}
fn throttle(self) -> Throttle<Self> {
let now = Instant::now();
Throttle {
stream: self,
start_time: now,
sleep: delay(now)
}
Throttle::new(self)
}
}