tokio-timer icon indicating copy to clipboard operation
tokio-timer copied to clipboard

Consider generalizing TimeoutStream / adding an IdleStream adapter

Open mehcode opened this issue 7 years ago • 0 comments

In my project I need to execute some action if a stream has not responded for some amount of time and then continue with normal operation of the stream; essentially, an idle callback.

I copied TimeoutStream into my project and modified a few lines. Instead of raising on error on timeout I invoke a closure and resume polling the stream.

// [...]

            Ok(Async::Ready(_)) => {
                // Timeout has elapsed, reest and continue
                self.sleep = self.timer.sleep(self.duration);
                (self.on_idle)();

                self.poll()
            }

// [...]

Would this IdleStream be a good fit for inclusion in this crate ?

mehcode avatar Nov 19 '17 07:11 mehcode