operator_debounce_time
The debounce_time operator emits the most recent upstream value only after
the specified duration passes without another emission.
Upstream completion and cancellation can happen instantly if there are no pending debounced values, otherwise it will complete or cancel once the pending debounced value has been emitted.
Upstream errors are immediately propagated downstream, cancelling any pending debounced value.
See Also
- AdsrOperator - Convert trigger signals into an ADSR envelope driven by the scheduler.
- DelayOperator - Shift emissions forward in time using the scheduler.
- FallbackWhenSilentOperator - Emit a fallback value on ticks where the source stayed silent.
- ObserveOnOperator - Re-emit upstream signals with the provided scheduler.
- SubscribeOnOperator - Schedule upstream subscription on the provided scheduler.
- ThrottleTimeOperator - Limit the frequency of downstream emissions.
Example
cargo run -p rx_core --example operator_debounce_time_example
let mut executor = MockExecutor::new_with_logging();
let scheduler = executor.get_scheduler_handle();
let mut subject = PublishSubject::<usize>::default();
let _subscription = subject
.clone()
.debounce_time(Duration::from_millis(1000), scheduler)
.subscribe(PrintObserver::new("debounce_time_operator"));
subject.next(1);
executor.tick(Duration::from_millis(500));
subject.next(2);
executor.tick(Duration::from_millis(1000));
subject.complete();
Output:
Ticking... (500ms)
Ticking... (1s)
debounce_time_operator - next: 2
debounce_time_operator - completed
debounce_time_operator - unsubscribed