listStreamProxy与listStreamPusherProxy支持key筛选参数

This commit is contained in:
xia-chu
2026-03-18 11:23:22 +08:00
parent 22a8a9a2ec
commit fa7b0639d8
2 changed files with 17 additions and 9 deletions

View File

@@ -295,12 +295,20 @@ public:
return it->second;
}
void for_each(const std::function<void(const std::string&, const Pointer&)>& cb) {
void for_each(const std::function<void(const std::string &, const Pointer &)> &cb, const std::string &key = {}) {
std::lock_guard<std::recursive_mutex> lck(_mtx);
auto it = _map.begin();
while (it != _map.end()) {
cb(it->first, it->second);
it++;
if (key.empty()) {
auto it = _map.begin();
while (it != _map.end()) {
cb(it->first, it->second);
++it;
}
} else {
auto it = _map.find(key);
if (it == _map.end()) {
throw std::invalid_argument("key not found: " + key);
}
cb(key, it->second);
}
}