Support subscribing to util::signal without the need to keep the subscription token

This commit is contained in:
Nikita Lisitsa 2024-07-19 21:14:38 +03:00
parent 403e24bf4c
commit d2ba791be1

View file

@ -22,6 +22,11 @@ namespace psemek::util
return token; return token;
} }
void subscribe_forever(subscriber callback) const
{
tokens_.push_back(subscribe(std::move(callback)));
}
void operator()(Args const & ... args) void operator()(Args const & ... args)
{ {
auto subscribers = std::move(subscribers_); auto subscribers = std::move(subscribers_);
@ -52,6 +57,7 @@ namespace psemek::util
private: private:
mutable std::vector<std::weak_ptr<subscriber>> subscribers_; mutable std::vector<std::weak_ptr<subscriber>> subscribers_;
mutable std::vector<subscription_token> tokens_;
}; };
} }