Skip to content

Commit 6c91f0b

Browse files
levkroppSploder12
authored andcommitted
[az] Use find_if to find next available az
1 parent ccaed18 commit 6c91f0b

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

src/platform/backends/shared/base_availability_zone_manager.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,16 @@ std::string BaseAvailabilityZoneManager::ZoneCollection::next_available()
159159
{
160160
std::unique_lock lock{mutex};
161161

162-
// Iterate through all zones starting with zone1 to find an available one
163-
for (auto zone_it = zones.begin(); zone_it != zones.end(); ++zone_it)
162+
// Locate the first available zone
163+
auto zone_it = std::find_if(zones.begin(), zones.end(), [](const auto& zone) {
164+
return zone->is_available();
165+
});
166+
167+
// Check if an available zone was found
168+
if (zone_it != zones.end())
164169
{
165-
if ((*zone_it)->is_available())
166-
{
167-
automatic_zone = zone_it;
168-
return (*zone_it)->get_name();
169-
}
170+
automatic_zone = zone_it;
171+
return (*zone_it)->get_name();
170172
}
171173

172174
// If none are available, throw an exception

0 commit comments

Comments
 (0)