Skip to content

Instantly share code, notes, and snippets.

@JohnMurray
Last active July 26, 2020 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnMurray/23e715af5f0d5be1c6b006423bc92a98 to your computer and use it in GitHub Desktop.
Save JohnMurray/23e715af5f0d5be1c6b006423bc92a98 to your computer and use it in GitHub Desktop.
template<BehaviorType T>
class RoundRobinRouter
: public Actor
, public T
{
const std::vector<actor_ref<T>> m_children;
std::vector<actor_ref<T>>::iterator m_it;
public:
RoundRobinRouter(std::vector<actor_ref<T>> const& actors)
: m_children(actors), m_it(children.begin()) {}
template<BehaviorReceives<T> Msg>
void receive(Msg const& msg) {
(*m_it).send(msg);
if (++m_it == m_children.end()) {
m_it = m_children.begin();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment