I would contribute another piece comparing C++ Future Extensions as already available via the Boost Futures implementation vs. native JavaScript promises.
Should be fun discovering their similarities.
E.g. future<X>::then([](future<X>){...}) <=> promise.then(function(x){ ... }))
Good idea?
Edit (August, 1st):
Just to collect ideas here:
| Feature |
JS |
C++ |
| eager execution |
new Promise(computation) |
std::async(computation) |
| lazy execution |
function task(){ return promise; } |
std::packaged_task(computation) |
| OR combination |
Promise.race([]) |
boost::when_any() |
| AND combination |
Promise.all([]) |
boost::when_all() |
| consumption |
promise.then |
boost::future<>::then |
| success factory |
Promise.resolve |
boost::make_ready_future |
| failure factory |
Promise.reject |
boost::make_exceptional_future |
Edit (Aug. 21st):
Found a C++ library for the Promises A+ Spec: xhawk18/promise-cpp.
- However evolved wrapping of Boost.Asio needs to be done. Which may be a concern when updating Boost.Asio which natively at least supports
std::future. 😞
- Couldn't yet find code to convert xhawk/promise to/from std::future/boost::future 😞
I would contribute another piece comparing C++ Future Extensions as already available via the Boost Futures implementation vs. native JavaScript promises.
Should be fun discovering their similarities.
E.g.
future<X>::then([](future<X>){...})<=>promise.then(function(x){ ... }))Good idea?
Edit (August, 1st):
Just to collect ideas here:
new Promise(computation)std::async(computation)function task(){ return promise; }std::packaged_task(computation)Promise.race([])boost::when_any()Promise.all([])boost::when_all()promise.thenboost::future<>::thenPromise.resolveboost::make_ready_futurePromise.rejectboost::make_exceptional_futureEdit (Aug. 21st):
Found a C++ library for the Promises A+ Spec: xhawk18/promise-cpp.
std::future. 😞