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 1a2ec073ca
Add tests for tasks that throw (#4)
* Add tests for tasks that throw

* Additional task types for throwing coverage
2020-10-12 17:29:47 -06:00

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