Skip to content

Instantly share code, notes, and snippets.

@jdmichaud
Created November 13, 2019 14:21
Show Gist options
  • Save jdmichaud/5cb0be6a7e1772ff8b8c10af51e1a874 to your computer and use it in GitHub Desktop.
Save jdmichaud/5cb0be6a7e1772ff8b8c10af51e1a874 to your computer and use it in GitHub Desktop.
Observable Design
typedef std::function<std::function<void()>(Observer<T>)> SubscriberFunction<T>;
interface Subscription<T> {
Subscription<T>(Observer<T>, SubscriberFunction<T>);
void unsubscribe();
}
interface Observer<T> {
void start(Subscription<T>);
void next(const T&);
void error(const std::exception&);
void complete();
}
interface Observable<T> {
Observable<T>(SubscriberFunction<T>);
Subscription &subscribe(Observer<T>);
Subscription &subscribe(std::function<void(const T&));
}
interface Subject<T> extends Observable<T> {
Subject<T>();
void next(const T&);
void error(const std::exception&);
void complete();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment