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_tap_next

crates.io ci codecov license

Run a callback for each next value while letting signals pass through.

See Also

  • TapOperator - Mirror all signals into another observer.
  • OnNextOperator - Invoke a callback for each value that can also decide whether to forward it.
  • OnSubscribeOperator - Run a callback when a subscription is established.
  • FinalizeOperator - Execute cleanup when the observable finishes or unsubscribes.

Example

cargo run -p rx_core --example operator_tap_next_example
let _subscription = (1..=5)
    .into_observable()
    .tap_next(|next| println!("hello {next}"))
    .subscribe(PrintObserver::new("tap_operator"));

Output:

hello 1
tap_operator - next: 1
hello 2
tap_operator - next: 2
hello 3
tap_operator - next: 3
hello 4
tap_operator - next: 4
hello 5
tap_operator - next: 5
tap_operator - completed
tap_operator - unsubscribed