operator_observe_on
The observe_on operator re-emits upstream next signals on the provided
scheduler.
Upstream completion and cancellation happen immediately when there are no pending scheduled values, otherwise they are deferred until scheduled work drains.
Upstream errors are forwarded immediately; any pending scheduled values are skipped because downstream closes.
See Also
- DebounceTimeOperator - Emit the most recent value after a period of silence.
- DelayOperator - Shift emissions forward in time using the scheduler.
- SubscribeOnOperator - Schedule upstream subscription on the provided scheduler.
- ThrottleTimeOperator - Limit the frequency of downstream emissions.
Example
cargo run -p rx_core --example operator_observe_on_example
use std::time::Duration;
use rx_core::prelude::*;
use rx_core_testing::MockExecutor;
fn main() {
let mut executor = MockExecutor::new_with_logging();
let scheduler = executor.get_scheduler_handle();
let _subscription = (1..=3)
.into_observable()
.observe_on(scheduler)
.subscribe(PrintObserver::new("observe_on_operator"));
executor.tick(Duration::from_millis(1));
}
Output:
Ticking... (0ns)
observe_on_operator - next: 1
observe_on_operator - next: 2
observe_on_operator - next: 3
observe_on_operator - completed
observe_on_operator - unsubscribed