Support subscribing to util::signal without the need to keep the subscription token
This commit is contained in:
parent
403e24bf4c
commit
d2ba791be1
1 changed files with 6 additions and 0 deletions
|
|
@ -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_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue