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

subject_replay

crates.io ci codecov license

Buffers the last N values and replays them to late subscribers.

See Also

  • PublishSubject - Forwards observed signals to active subscribers without replaying values, but terminal state is replayed.
  • AsyncSubject - Reduces observed values into one and emits it on completion, replaying the result to late subscribers.
  • BehaviorSubject - Always holds a value that is replayed to late subscribers.
  • ProvenanceSubject - BehaviorSubject that also stores an additional filtering value to track provenance.

Example

cargo run -p rx_core --example subject_replay_example
use rx_core::prelude::*;

fn main() {
    let mut subject = ReplaySubject::<2, i32>::default();

    let _s = subject
        .clone()
        .subscribe(PrintObserver::<i32>::new("hello"));

    subject.next(1);
    subject.next(2);
    subject.next(3);

    let _s2 = subject
        .clone()
        .subscribe(PrintObserver::<i32>::new("hi"));

    subject.next(4);
    subject.next(5);
}

Output:

hello - next: 1
hello - next: 2
hello - next: 3
hi - next: 2
hi - next: 3
hi - next: 4
hello - next: 4
hi - next: 5
hello - next: 5
hi - unsubscribed
hello - unsubscribed