pub trait Debounce<T>where
T: ObservableType,{
// Required methods
fn debounce(&mut self) -> Pipe<T>;
fn debounce_for(&mut self, duration: Duration) -> Pipe<T>;
}Required Methods§
Sourcefn debounce(&mut self) -> Pipe<T>
fn debounce(&mut self) -> Pipe<T>
Attaches a 100ms debounce operator to the end of the chain and forwards the pipe, see this method for details
Sourcefn debounce_for(&mut self, duration: Duration) -> Pipe<T>
fn debounce_for(&mut self, duration: Duration) -> Pipe<T>
Attaches a debounce operator to the end of the chain and forwards the pipe
debounce_for is used for tapping into a debounced event stream. This
means events will only be emitted after the stream is idle for duration
amount of time.
§Example
use drumbeat::event::subject::{BasicSubject, Subject};
use drumbeat::event::ops::*;
use std::time::Duration;
let subject = BasicSubject::new();
let rx = subject.observe()
.pipe()
.take(100)
.assert_count(100)
.debounce_for(Duration::from_millis(400))
.collect();
for i in 0..100 {
subject.next(i);
if i == 50 {
std::thread::sleep(Duration::from_millis(500));
}
}
assert_eq!(rx.recv().unwrap(), [50]);