0.5.0-alpha.0
This commit is contained in:
@@ -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;
|
||||
|
||||
41
crates/streams/src/print_on_done.rs
Normal file
41
crates/streams/src/print_on_done.rs
Normal 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,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user