Skip to content

Instantly share code, notes, and snippets.

@JohnMurray
Last active July 28, 2020 00:31
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/9f40d1dce4a46ad51fa21d1002f26626 to your computer and use it in GitHub Desktop.
Save JohnMurray/9f40d1dce4a46ad51fa21d1002f26626 to your computer and use it in GitHub Desktop.
class Actor {
std::deque<std::function<void()>> m_messages;
public:
virtual ~Actor() = default;
void enqueue(std::function<void()> const& func) {
m_messages.push_back(func);
}
void process_message() {
if (m_messages.begin() != m_messages.end()) {
(*m_messages.begin())();
m_messages.pop_front();
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment