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

Unsubscribe / Multiple subscriptions #11

Open
rzeldent opened this issue Jan 17, 2023 · 2 comments
Open

Unsubscribe / Multiple subscriptions #11

rzeldent opened this issue Jan 17, 2023 · 2 comments

Comments

@rzeldent
Copy link

To subscribe to an observable this can be done by creating a class that implements IObserver and subscibe.
However, it is not possible to unsubscribe. When subscribing a reference should be returned so that an observer can unsubscribe.

The IObserver *_observer; should be iterable, so become a list/array and all the observers should be called.

See, for example the Observable base:

  • Subscibe does not return a reference, but void.
  • The _observer is only a single observer. but should be some list.
template <typename T>
class ObservableProperty : public Observable<T>
{
public:
	void operator = (const T&);
	ObservableProperty();
	void Subscribe(IObserver<T> &) override;
	void Finish();
	void Reset() override;

private:
	IObserver<T> *_observer;
	bool _complete = false;
};
@rzeldent
Copy link
Author

rzeldent commented Jan 18, 2023

Was looking on Github and https://github.com/ferreirocm/SimpleObservable has a list and a mechanism to unsubscribe.
The (address of the) observer can be used to unsubscribe..
This might give some inspiration?

@rzeldent
Copy link
Author

Is implemented. See PR

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

1 participant