Created
February 18, 2023 20:27
-
-
Save nboutin/7775e59e8f774336bf8aca5c3e545743 to your computer and use it in GitHub Desktop.
Revisions
-
nboutin created this gist
Feb 18, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ // https://www.youtube.com/watch?v=nLSm3Haxz0I class EventSource { void add(Listener& listener); void remove(Listener& listener); public: [[nodiscard]] Subscription subscribe(Listener& listener) { return Subscription(*this, listener); } }; class EventSource::Subscription { Subscription(EventSource& source, Listener& listener) : source_(source), listener_(listener) { source_.add_listener(listener_); } ~Subscription() { source_.remove(listener_);} // special function members };