mirror of
https://gitlab.com/niansa/libcrosscoro.git
synced 2025-03-06 20:53:32 +01:00
30 lines
616 B
C++
30 lines
616 B
C++
#pragma once
|
|
|
|
#include "coro/scheduler.hpp"
|
|
#include "coro/task.hpp"
|
|
|
|
namespace coro
|
|
{
|
|
template<typename task_type>
|
|
auto sync_wait(task_type&& task) -> decltype(auto)
|
|
{
|
|
while (!task.is_ready())
|
|
{
|
|
task.resume();
|
|
}
|
|
return task.promise().return_value();
|
|
}
|
|
|
|
template<typename... tasks>
|
|
auto sync_wait_all(tasks&&... awaitables) -> void
|
|
{
|
|
scheduler s{scheduler::options{
|
|
.reserve_size = sizeof...(awaitables), .thread_strategy = scheduler::thread_strategy_t::manual}};
|
|
|
|
(s.schedule(std::move(awaitables)), ...);
|
|
|
|
while (s.process_events() > 0)
|
|
;
|
|
}
|
|
|
|
} // namespace coro
|