mirror of
https://gitlab.com/niansa/libcrosscoro.git
synced 2025-03-06 20:53:32 +01:00
32 lines
624 B
C++
32 lines
624 B
C++
#pragma once
|
|
|
|
#include "coro/task.hpp"
|
|
#include "coro/scheduler.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
|