Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Audit Nomenclature: Subscription | Subscriber | Observer #206

Open
Trequetrum opened this issue Dec 20, 2022 · 1 comment
Open

Audit Nomenclature: Subscription | Subscriber | Observer #206

Trequetrum opened this issue Dec 20, 2022 · 1 comment

Comments

@Trequetrum
Copy link
Contributor

This codebase likes to shift back and forth between various nomenclature for various actors. It's not clear whether to call a consumer of values a Subscriber or an Observer. The trait's name is Observer:

pub trait Observer {
  type Item;
  type Err;
  fn next(&mut self, value: Self::Item);
  fn error(&mut self, err: Self::Err);
  fn complete(&mut self);
}

This agrees with ReactiveX documentation elsewhere (Ex: It's most popular implementation RxJS), though this isn't as consistent as we might hope. Throughout the code, tests/ docs instances of observers are often called subscribers. rxRust should endeavor to choose one name and stick with it everywhere.

Is the following subscriber is actually an observer? It seems to implement the Observer trait.

let o = observable::create(|subscriber| {
    subscriber.complete();
})

The docs also often refer to Subscriptions or SubscriptionLike as Subscriber meaning that sometimes Subscriber means Observer and sometimes it means SubscriptionLike. For example:

/// Returns a new Observable that multicast (shares) the original
/// Observable. As long as there is at least one Subscriber this
/// Observable will be subscribed and emitting data.

Subscribing with an Observer, returns a SubscriptionLike (via SubscriptionWrapper) and it's ostensibly this Subscription that determines how long an Observable lives.

I'm not sure I get all the nuance at work here, but I think some tightening of the common vernacular might help!

@M-Adoo
Copy link
Collaborator

M-Adoo commented Feb 4, 2023

@Trequetrum sorry for the too late replay, I'm busing work on another library and forget this thread before.

Subscribing with an Observer, returns a SubscriptionLike (via SubscriptionWrapper) and it's ostensibly this Subscription that determines how long an Observable lives.

Yes, you're right.

Subscriber is an object both implement SubscriptionLike and Observer.

And In this month I refactor rxRust in #215, and I think it's more clear. Only three major trait Observer, Observable and Subscription, and Subscriber is a struct both implemented Observer and Subscription.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants