Skip to content

Commit

Permalink
ssx/async_algorithm: disallow passing a coroutine to ssx::async_for_each
Browse files Browse the repository at this point in the history
In fact fail the compliation if the function returns non-void [[nodiscard]],
which holds for coroutines thanks to ss::future class [[nodiscard]] annotation.

Calling ssx::async_for_each of course does not make much sense, as its purpose
is to inject scheduling points. However it can be done by mistake, e.g. when
a function return type was changed from void to ss::future<>.
  • Loading branch information
bashtanov committed Oct 1, 2024
1 parent 732bc81 commit 7d13f36
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/v/ssx/async_algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ template<std::random_access_iterator I, typename Fn>
iter_size<I> for_each_limit(const I begin, const I end, ssize_t limit, Fn f) {
auto chunk_size = std::min(limit, end - begin);
I chunk_end = begin + chunk_size;
// std::for_each discards [[nodiscard]] callable result, check explicitly
if (false) {
f(*begin);
}
std::for_each(begin, chunk_end, std::move(f));
return {chunk_end, chunk_size};
}
Expand Down

0 comments on commit 7d13f36

Please sign in to comment.