1
0
Fork 0
mirror of https://gitlab.com/niansa/libcrosscoro.git synced 2025-03-06 20:53:32 +01:00
libcrosscoro/inc/coro/sync_wait.hpp
Josh Baldwin 303cc3384c
Issue 5/clang format (#6)
* clang-format all existing files

* Add detailed comments for event
2020-10-14 08:53:00 -06:00

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