#include <boost/capy/error.hpp>
#include <boost/capy/ex/async_event.hpp>
#include <boost/capy/ex/run_async.hpp>
#include <boost/capy/ex/thread_pool.hpp>
#include <boost/capy/io_task.hpp>
#include <boost/capy/task.hpp>
#include <boost/capy/when_any.hpp>
#include <iostream>
namespace capy = boost::capy;
// Returns immediately with a canceled error.
capy::io_task<> fn1() { co_return {capy::error::canceled}; }
// Waits on an event that is never triggered.
capy::io_task<> fn2()
{
capy::async_event evt;
co_return co_await evt.wait();
}
// BUG: This hangs. `when_any` should complete as soon as `fn1()`
// returns, cancelling `fn2()`. Instead, `mytest()` never returns.
capy::task<> mytest()
{
auto u = co_await capy::when_any(fn1(), fn2());
std::cout << "Index: " << u.index() << std::endl;
}
int main()
{
capy::thread_pool ctx;
capy::run_async(ctx.get_executor())(mytest());
ctx.join();
}
Expectation: fn2 gets cancelled, mytest finishes.
Actual behavior: mytest will never complete.
This behavior doesn't happen if f1 finishes successfully.
Prevents the Boost.Redis port from working.
Expectation:
fn2gets cancelled,mytestfinishes.Actual behavior:
mytestwill never complete.This behavior doesn't happen if
f1finishes successfully.Prevents the Boost.Redis port from working.