Skip to content

Instantly share code, notes, and snippets.

@Ge0
Created June 10, 2019 21:13
Show Gist options
  • Save Ge0/200c5a04df3fd23e11efe22693b5ee02 to your computer and use it in GitHub Desktop.
Save Ge0/200c5a04df3fd23e11efe22693b5ee02 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <boost/asio.hpp>
class Contextable {
public:
Contextable(boost::asio::io_context& ctx) : m_ioContext(ctx) {}
protected:
boost::asio::io_context& m_ioContext;
};
class Consumer : public Contextable{
public:
Consumer(boost::asio::io_context& ctx) : Contextable(ctx) {}
void completion(std::string str) {
std::cout << "Received " << str << std::endl;
}
};
int main() {
boost::asio::io_context ctx;
Consumer c(ctx);
ctx.post([&]() { c.completion("foo"); });
ctx.run();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment