Arduino-ReactiveArduino
Arduino-ReactiveArduino copied to clipboard
Unsubscribe / Multiple subscriptions
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;
};
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?
Is implemented. See PR