emlabcpp
modern opinionated embedded C++ library
round_robin_executor.h
Go to the documentation of this file.
1 
24 #pragma once
25 
26 #include <emlabcpp/algorithm.h>
29 
30 namespace emlabcpp::coro
31 {
32 template < typename Container >
34 {
35  std::size_t i = 0;
36 
37  while ( true ) {
38 
39  auto& cor = coros[i];
40  i = ( i + 1 ) % std::size( coros );
41 
42  if ( cor.done() ) {
43  if ( i == 0 && all_of( coros ) )
44  co_return;
45  continue;
46  }
47 
48  auto const* out = cor.get_request();
49 
50  if ( out == nullptr )
51  co_return;
52 
53  auto resp = co_yield *out;
54  cor.store_reply( resp );
55 
56  if ( !cor.tick() )
57  co_return;
58  }
59 }
60 
61 } // namespace emlabcpp::coro
Definition: memory_resource.h:33
MIT License.
Definition: data_promise.h:27
Container::value_type round_robin_run(pmr::memory_resource &, Container coros)
Definition: round_robin_executor.h:33
std::variant< int64_t, float, bool, string_buffer > value_type
Definition: base.h:51
constexpr bool all_of(Container &&cont, PredicateCallable &&f=std::identity())
Returns true if call to predicate 'f(x)' returns true for all items in 'cont'.
Definition: algorithm.h:342