generic_server: use async function in for_each_gently()
In the following patch, we will add a method to update service levels parameters for each cql connections. To support this, this patch allows to pass async function as a parameter to `for_each_gently()` method.
This commit is contained in:
@@ -40,13 +40,12 @@ connection::~connection()
|
||||
_server.maybe_stop();
|
||||
}
|
||||
|
||||
future<> server::for_each_gently(noncopyable_function<void(connection&)> fn) {
|
||||
future<> server::for_each_gently(noncopyable_function<future<>(connection&)> fn) {
|
||||
_gentle_iterators.emplace_front(*this);
|
||||
std::list<gentle_iterator>::iterator gi = _gentle_iterators.begin();
|
||||
return seastar::do_until([ gi ] { return gi->iter == gi->end; },
|
||||
[ gi, fn = std::move(fn) ] {
|
||||
fn(*(gi->iter++));
|
||||
return make_ready_future<>();
|
||||
return fn(*(gi->iter++));
|
||||
}
|
||||
).finally([ this, gi ] { _gentle_iterators.erase(gi); });
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ protected:
|
||||
|
||||
virtual future<> unadvertise_connection(shared_ptr<connection> conn);
|
||||
|
||||
future<> for_each_gently(noncopyable_function<void(connection&)>);
|
||||
future<> for_each_gently(noncopyable_function<future<>(connection&)>);
|
||||
|
||||
void maybe_stop();
|
||||
};
|
||||
|
||||
@@ -2022,9 +2022,10 @@ void cql_server::response::write(const cql3::prepared_metadata& m, uint8_t versi
|
||||
|
||||
future<utils::chunked_vector<client_data>> cql_server::get_client_data() {
|
||||
utils::chunked_vector<client_data> ret;
|
||||
co_await for_each_gently([&ret] (const generic_server::connection& c) {
|
||||
co_await for_each_gently([&ret] (const generic_server::connection& c) -> future<> {
|
||||
const connection& conn = dynamic_cast<const connection&>(c);
|
||||
ret.emplace_back(conn.make_client_data());
|
||||
return make_ready_future<>();
|
||||
});
|
||||
co_return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user