0.5.0-alpha.0

This commit is contained in:
Dominik Werder
2023-12-11 15:55:18 +01:00
parent 3d110f1ea6
commit 11d35e0cb6
8 changed files with 72 additions and 64 deletions

View File

@@ -7,6 +7,7 @@ pub mod generators;
pub mod itemclone;
pub mod needminbuffer;
pub mod plaineventsjson;
pub mod print_on_done;
pub mod rangefilter2;
pub mod slidebuf;
pub mod tcprawclient;

View File

@@ -0,0 +1,41 @@
use futures_util::Stream;
use futures_util::StreamExt;
use std::pin::Pin;
use std::task::Context;
use std::task::Poll;
use std::time::Instant;
pub struct PrintOnDone<INP> {
ts_ctor: Instant,
inp: INP,
on_done: Pin<Box<dyn Fn(Instant) -> () + Send>>,
}
impl<INP> PrintOnDone<INP> {
pub fn new(inp: INP, on_done: Pin<Box<dyn Fn(Instant) -> () + Send>>) -> Self {
Self {
ts_ctor: Instant::now(),
inp,
on_done,
}
}
}
impl<INP> Stream for PrintOnDone<INP>
where
INP: Stream + Unpin,
{
type Item = <INP as Stream>::Item;
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
use Poll::*;
match self.inp.poll_next_unpin(cx) {
Ready(Some(x)) => Ready(Some(x)),
Ready(None) => {
(self.on_done)(self.ts_ctor);
Ready(None)
}
Pending => Pending,
}
}
}