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_subscribe_on

crates.io ci codecov license

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

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