Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

operator_fallback_when_silent

crates.io ci codecov license

Emit a fallback value on ticks where the source stayed silent.

See Also

Example

cargo run -p rx_core --example operator_fallback_when_silent_example
use std::time::Duration;

use rx_core::prelude::*;
use rx_core_testing::MockExecutor;

fn main() {
  let mut executor = MockExecutor::default();
  let scheduler = executor.get_scheduler_handle();

  let mut subject = PublishSubject::<i32>::default();

  let mut subscription = subject
    .clone()
    .fallback_when_silent(|_, _, _| Default::default(), scheduler)
    .subscribe(PrintObserver::<i32>::new("fallback_when_silent"));

  subject.next(1);
  executor.tick(Duration::from_millis(200));
  subject.next(2);
  executor.tick(Duration::from_millis(200));
  // Silence
  executor.tick(Duration::from_millis(200));
  subject.next(3);
  executor.tick(Duration::from_millis(200));

  subscription.unsubscribe();
}
fallback_when_silent - next: 1
fallback_when_silent - next: 2
fallback_when_silent - next: 0
fallback_when_silent - next: 3
fallback_when_silent - unsubscribed