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_on_subscribe

crates.io ci codecov license

Run a callback when a subscription is established.

See Also

  • TapOperator - Mirror all signals into another observer.
  • TapNextOperator - Run a callback for each next value while letting signals pass through.
  • OnNextOperator - Invoke a callback for each value that can also decide whether to forward it.
  • FinalizeOperator - Execute cleanup when the observable finishes or unsubscribes.

Example

cargo run -p rx_core --example operator_on_subscribe_example
let _subscription = (1..=5)
    .into_observable()
    .on_subscribe(|destination| destination.next(99))
    .subscribe(PrintObserver::new("on_subscribe_operator"));

Output:

on_subscribe_operator - next: 99
on_subscribe_operator - next: 1
on_subscribe_operator - next: 2
on_subscribe_operator - next: 3
on_subscribe_operator - next: 4
on_subscribe_operator - next: 5
on_subscribe_operator - completed
on_subscribe_operator - unsubscribed