Portable concurrency
0.11.0
|
std::future
done right. Simple to use portable implementation of the future/promise API inspired by the C++ Extensions for Concurrency TS and some parts of A Unified Executors Proposal for C++.
when_all
/when_any
composition of futures future<future<T>>
transparently unwrapped to future<T>
future<shared_future<T>>
transparently unwrapped to shred_future<T>
pc::async
/pc::packaged_task
or attached to intermediate futures as continuations may not be executed at all if future
or all shared_future
's on the result of continuations chain are destroyed.future::detach()
and shared_future::detach()
functions allows to destroy future without cancelation of any tasks. ```cpp auto future = pc::async(pool.executor(), important_calculation) .next(io.get_executor(), important_io) .detach() .next(pool.executor(), not_so_important_calculations); ``
important_calculationand
important_ioare guarantied to be executed even in case of premature future destruction. *
promise::is_awaiten()allows to check if there is a
futureor
shared_futurewaiting for value to be set on this
promiseobject. *
promise::promise(canceler_arg_t, CancelAction)` constructor allows to specify action which is called in case of cancelation via future destruction.then
overload to check if task is canceled from the continuations function ```cpp pc::future<std::string> res = pc::async(pool.executor(), [] {return 42;}) .then([](pc::promise<std::string> p, pc::future<int> f) { std::string res; while (has_work_to_do()) { do_next_step(res, f); if (!p.is_awaiten()) return; } p.set_value(res); }); ```mkdir -p build/debug cd build/debug conan remote add pdeps https://api.bintray.com/conan/pdeps/deps conan install --build=missing ../.. cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug ../.. ninja ninja test