Arduino-ReactiveArduino icon indicating copy to clipboard operation
Arduino-ReactiveArduino copied to clipboard

Unsubscribe / Multiple subscriptions

Open rzeldent opened this issue 2 years ago • 2 comments
trafficstars

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<T> *_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 avatar Jan 17 '23 13:01 rzeldent

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 avatar Jan 18 '23 15:01 rzeldent

Is implemented. See PR

rzeldent avatar Jan 20 '23 00:01 rzeldent