From d2ba791be1d545cf023634cacc30faf371b4258e Mon Sep 17 00:00:00 2001 From: lisyarus Date: Fri, 19 Jul 2024 21:14:38 +0300 Subject: [PATCH] Support subscribing to util::signal without the need to keep the subscription token --- libs/util/include/psemek/util/signal.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/util/include/psemek/util/signal.hpp b/libs/util/include/psemek/util/signal.hpp index 73893fc0..b1858b5a 100644 --- a/libs/util/include/psemek/util/signal.hpp +++ b/libs/util/include/psemek/util/signal.hpp @@ -22,6 +22,11 @@ namespace psemek::util return token; } + void subscribe_forever(subscriber callback) const + { + tokens_.push_back(subscribe(std::move(callback))); + } + void operator()(Args const & ... args) { auto subscribers = std::move(subscribers_); @@ -52,6 +57,7 @@ namespace psemek::util private: mutable std::vector> subscribers_; + mutable std::vector tokens_; }; }