chriskohlhoff / asio

Asio C++ Library
http://think-async.com/Asio
4.88k stars 1.21k forks source link

make_parallel_group can't deal with empty range #1375

Open criatura2 opened 11 months ago

criatura2 commented 11 months ago

The code below never calls its continuation and exits without error.

#include <asio.hpp>
#include <asio/experimental/parallel_group.hpp>

#include <iostream>

using asio::experimental::make_parallel_group;
using asio::experimental::wait_for_all;

int main()
{
    try {
        asio::io_context ioc;

        std::vector<decltype(std::declval<asio::steady_timer>().async_wait(asio::deferred))> ops;

        make_parallel_group(ops).async_wait(wait_for_all(), [](auto...)
        {
            std::cout << "Never called." << std::endl;
        });

        ioc.run();
    } catch (std::exception const& e) {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }
}

IMO, it shouldn't be so silent about this problem. Better yet would be to find a way to pass an executor for immediate completions.