tgockel / zookeeper-cpp

A ZooKeeper client for C++.
http://tgockel.github.io/zookeeper-cpp/
Apache License 2.0
148 stars 40 forks source link

Allow use of boost::future as zk::future #112

Closed Jauler closed 3 years ago

Jauler commented 4 years ago

Hey,

So we would like to use boost::future also therefore I made this implementation. This might not be ideal solution, but it solves my problem.

Most of the 'not ideal solution' comes from the fact, that calling boost::promise::set_exception() with boost::current_exception() requires that exception would be either thrown with boost::throw_exception() or wrapped in boost::enable_current_exception(...) (I tested on gcc 7 and without wrapping, exception rethrown was of wrong type). To work around this I added zk::throw_exception() wrapper which either throws directly for std::future case or does necessary wrapping when using boost::future.

Another problem was that boost::enable_current_exception(), requires derived exception types. Therefore I removed final declarations from error types.

Also I introduced zk::exception_ptr, zk::current_exception() and zk::async() to map either to std variants or boost ones for compatability.

This most likely solves #108 and #107

tgockel commented 3 years ago

Apparently I forgot about this...sorry. This looks really good, but unfortunately, it won't build because CI doesn't work for old Ubuntu versions. I squashed and rebased these changes over to a new PR -- https://github.com/tgockel/zookeeper-cpp/pull/117 .

Thanks for your work and patience!