operator_subscribe_on
The subscribe_on operator schedules the subscription to the upstream
observable on the provided scheduler.
This only affects when the upstream subscription starts. It does not alter
when upstream next, error, or complete signals are emitted.
The subscription can be delayed with subscribe_on_with_delay.
See Also
- DebounceTimeOperator - Emit the most recent value after a period of silence.
- DelayOperator - Shift emissions forward in time using the scheduler.
- ObserveOnOperator - Re-emit upstream signals with the provided scheduler.
- ThrottleTimeOperator - Limit the frequency of downstream emissions.
- RetryOperator - Resubscribe on error up to the configured retry count.
Example
cargo run -p rx_core --example operator_subscribe_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()
.subscribe_on(scheduler)
.subscribe(PrintObserver::new("subscribe_on_operator"));
executor.tick(Duration::from_millis(0));
}
Output:
Ticking... (0ns)
subscribe_on_operator - next: 1
subscribe_on_operator - next: 2
subscribe_on_operator - next: 3
subscribe_on_operator - completed
subscribe_on_operator - unsubscribed