cppcoro/include/cppcoro/sync_wait.hpp
Lewis Baker d7ef66dfb1 Fix sync_wait() under latest MSVC compiler.
A compiler workaround was only being applied for compiler versions
below a known version and would break whenever a new version comes
out without a fix. It now just applies the workaround for all MSVC
versions. I'll re-add the version limit once MSVC actually fixes
the bug.
2017-11-19 06:55:30 +10:30

36 lines
1.1 KiB
C++

///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Lewis Baker
// Licenced under MIT license. See LICENSE.txt for details.
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPCORO_SYNC_WAIT_HPP_INCLUDED
#define CPPCORO_SYNC_WAIT_HPP_INCLUDED
#include <cppcoro/detail/lightweight_manual_reset_event.hpp>
#include <cppcoro/detail/sync_wait_task.hpp>
#include <cppcoro/awaitable_traits.hpp>
#include <cstdint>
#include <atomic>
namespace cppcoro
{
template<typename AWAITABLE>
auto sync_wait(AWAITABLE&& awaitable)
-> typename cppcoro::awaitable_traits<AWAITABLE&&>::await_result_t
{
#if CPPCORO_COMPILER_MSVC
// HACK: Need to explicitly specify template argument to make_sync_wait_task
// here to work around a bug in MSVC when passing parameters by universal
// reference to
auto task = detail::make_sync_wait_task<AWAITABLE>(awaitable);
#else
auto task = detail::make_sync_wait_task(std::forward<AWAITABLE>(awaitable));
#endif
detail::lightweight_manual_reset_event event;
task.start(event);
event.wait();
return task.result();
}
}
#endif