Код: Выделить всё
#include
asio::awaitable doit(char ch)
{
for (int i = 0; i < 5; ++i) {
fprintf(stderr, "%c %d\n", ch, i);
asio::steady_timer t(co_await asio::this_coro::executor);
t.expires_after(std::chrono::seconds(0));
co_await t.async_wait(asio::use_awaitable);
}
}
int main()
{
asio::io_context ctx;
co_spawn(ctx, doit('A'), asio::detached);
co_spawn(ctx, doit('B'), asio::detached);
ctx.run();
return 0;
}
Код: Выделить всё
A 0
B 0
A 1
B 1
A 2
B 2
A 3
B 3
A 4
B 4
В моем приложении я хочу, чтобы длительные задачи (несколько мс) приводили к выполнению в нескольких точках и давали изменение ожидающих задач в io_context для запуска.
Есть ли более идиоматический подход, чем этот хак Steady_timer?>
Подробнее здесь: https://stackoverflow.com/questions/798 ... eady-tasks
Мобильная версия