Commit 53874b38 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

Internally rename await in folly/fibers/

Summary: [Folly] Internally rename `await` in `folly/fibers/` since some versions of MSVC effectively `#define await co_await` breaking the build - except it's not really a `#define` and there is no reliable way to detect it.

Reviewed By: Orvid

Differential Revision: D23882811

fbshipit-source-id: 836bebcbcfe01ce39c873202b67796efafa1c366
parent acf28118
...@@ -73,7 +73,7 @@ inline void TaskIterator<T>::reserve(size_t n) { ...@@ -73,7 +73,7 @@ inline void TaskIterator<T>::reserve(size_t n) {
size_t tasksLeft = context_->totalTasks - context_->results.size(); size_t tasksLeft = context_->totalTasks - context_->results.size();
n = std::min(n, tasksLeft); n = std::min(n, tasksLeft);
await([this, n](Promise<void> promise) { await_async([this, n](Promise<void> promise) {
context_->tasksToFulfillPromise = n; context_->tasksToFulfillPromise = n;
context_->promise.assign(std::move(promise)); context_->promise.assign(std::move(promise));
}); });
......
...@@ -614,11 +614,11 @@ FiberManager::FiberManager( ...@@ -614,11 +614,11 @@ FiberManager::FiberManager(
} }
template <typename F> template <typename F>
typename FirstArgOf<F>::type::value_type inline await(F&& func) { typename FirstArgOf<F>::type::value_type inline await_async(F&& func) {
typedef typename FirstArgOf<F>::type::value_type Result; typedef typename FirstArgOf<F>::type::value_type Result;
typedef typename FirstArgOf<F>::type::baton_type BatonT; typedef typename FirstArgOf<F>::type::baton_type BatonT;
return Promise<Result, BatonT>::await(std::forward<F>(func)); return Promise<Result, BatonT>::await_async(std::forward<F>(func));
} }
template <typename F> template <typename F>
......
...@@ -678,7 +678,13 @@ inline void addTaskFinallyEager(F&& func, G&& finally) { ...@@ -678,7 +678,13 @@ inline void addTaskFinallyEager(F&& func, G&& finally) {
* @return data which was used to fulfill the promise. * @return data which was used to fulfill the promise.
*/ */
template <typename F> template <typename F>
typename FirstArgOf<F>::type::value_type inline await(F&& func); typename FirstArgOf<F>::type::value_type inline await_async(F&& func);
#if !defined(_MSC_VER)
template <typename F>
FOLLY_ERASE typename FirstArgOf<F>::type::value_type await(F&& func) {
return await_async(static_cast<F&&>(func));
}
#endif
/** /**
* If called from a fiber, immediately switches to the FiberManager's context * If called from a fiber, immediately switches to the FiberManager's context
......
...@@ -92,7 +92,8 @@ void Promise<T, BatonT>::setWith(F&& func) { ...@@ -92,7 +92,8 @@ void Promise<T, BatonT>::setWith(F&& func) {
template <class T, class BatonT> template <class T, class BatonT>
template <class F> template <class F>
typename Promise<T, BatonT>::value_type Promise<T, BatonT>::await(F&& func) { typename Promise<T, BatonT>::value_type Promise<T, BatonT>::await_async(
F&& func) {
folly::Try<value_type> result; folly::Try<value_type> result;
std::exception_ptr funcException; std::exception_ptr funcException;
......
...@@ -80,7 +80,14 @@ class Promise { ...@@ -80,7 +80,14 @@ class Promise {
* @return data which was used to fulfill the promise. * @return data which was used to fulfill the promise.
*/ */
template <class F> template <class F>
static value_type await(F&& func); static value_type await_async(F&& func);
#if !defined(_MSC_VER)
template <class F>
FOLLY_ERASE static value_type await(F&& func) {
return await_sync(static_cast<F&&>(func));
}
#endif
private: private:
Promise(folly::Try<T>& value, BatonT& baton); Promise(folly::Try<T>& value, BatonT& baton);
......
...@@ -52,7 +52,7 @@ collectN(InputIterator first, InputIterator last, size_t n) { ...@@ -52,7 +52,7 @@ collectN(InputIterator first, InputIterator last, size_t n) {
}; };
auto context = std::make_shared<Context>(n); auto context = std::make_shared<Context>(n);
await([first, last, context](Promise<void> promise) mutable { await_async([first, last, context](Promise<void> promise) mutable {
context->promise = std::move(promise); context->promise = std::move(promise);
for (size_t i = 0; first != last; ++i, ++first) { for (size_t i = 0; first != last; ++i, ++first) {
addTask([i, context, f = std::move(*first)]() { addTask([i, context, f = std::move(*first)]() {
...@@ -106,7 +106,7 @@ collectN(InputIterator first, InputIterator last, size_t n) { ...@@ -106,7 +106,7 @@ collectN(InputIterator first, InputIterator last, size_t n) {
}; };
auto context = std::make_shared<Context>(n); auto context = std::make_shared<Context>(n);
await([first, last, context](Promise<void> promise) mutable { await_async([first, last, context](Promise<void> promise) mutable {
context->promise = std::move(promise); context->promise = std::move(promise);
for (size_t i = 0; first != last; ++i, ++first) { for (size_t i = 0; first != last; ++i, ++first) {
addTask([i, context, f = std::move(*first)]() { addTask([i, context, f = std::move(*first)]() {
......
...@@ -52,7 +52,10 @@ struct await_fn { ...@@ -52,7 +52,10 @@ struct await_fn {
* for the wrapper to serve its intended purpose (the best way to enforce this * for the wrapper to serve its intended purpose (the best way to enforce this
* is static analysis) * is static analysis)
*/ */
FOLLY_DEFINE_CPO(await_fn, await) FOLLY_DEFINE_CPO(await_fn, await_async)
#if !defined(_MSC_VER)
static constexpr auto& await = await_async;
#endif
/** /**
* Asynchronous fiber result wrapper * Asynchronous fiber result wrapper
...@@ -145,11 +148,11 @@ explicit Async(T)->Async<T>; ...@@ -145,11 +148,11 @@ explicit Async(T)->Async<T>;
*/ */
template <typename T> template <typename T>
T&& init_await(Async<T>&& async) { T&& init_await(Async<T>&& async) {
return await(std::move(async)); return await_async(std::move(async));
} }
inline void init_await(Async<void>&& async) { inline void init_await(Async<void>&& async) {
await(std::move(async)); await_async(std::move(async));
} }
// is_async // is_async
......
...@@ -113,7 +113,8 @@ Async<TResult> collectAllImpl(T&& firstTask, Ts&&... tasks) { ...@@ -113,7 +113,8 @@ Async<TResult> collectAllImpl(T&& firstTask, Ts&&... tasks) {
Baton b; Baton b;
auto taskFunc = [&](auto& outref, auto&& task) -> Async<void> { auto taskFunc = [&](auto& outref, auto&& task) -> Async<void> {
await(executeAndMaybeAssign(outref, std::forward<decltype(task)>(task))); await_async(
executeAndMaybeAssign(outref, std::forward<decltype(task)>(task)));
--numPending; --numPending;
if (numPending == 0) { if (numPending == 0) {
...@@ -137,7 +138,7 @@ Async<TResult> collectAllImpl(T&& firstTask, Ts&&... tasks) { ...@@ -137,7 +138,7 @@ Async<TResult> collectAllImpl(T&& firstTask, Ts&&... tasks) {
std::forward<Ts>(tasks)...); std::forward<Ts>(tasks)...);
// Use the current fiber to execute first task // Use the current fiber to execute first task
await(taskFunc(std::get<0>(result), std::forward<T>(firstTask))); await_async(taskFunc(std::get<0>(result), std::forward<T>(firstTask)));
// Wait for other tasks to complete // Wait for other tasks to complete
b.wait(); b.wait();
......
...@@ -79,7 +79,7 @@ Async<std::tuple<lift_unit_t<async_invocable_inner_type_t<Ts>>...>> collectAll( ...@@ -79,7 +79,7 @@ Async<std::tuple<lift_unit_t<async_invocable_inner_type_t<Ts>>...>> collectAll(
Ts&&... tasks) { Ts&&... tasks) {
auto future = folly::collectAllUnsafe(addFiberFuture( auto future = folly::collectAllUnsafe(addFiberFuture(
std::forward<Ts>(tasks), FiberManager::getFiberManager())...); std::forward<Ts>(tasks), FiberManager::getFiberManager())...);
auto tuple = await(futureWait(std::move(future))); auto tuple = await_async(futureWait(std::move(future)));
return Async(folly::unwrapTryTuple(std::move(tuple))); return Async(folly::unwrapTryTuple(std::move(tuple)));
} }
......
...@@ -30,7 +30,7 @@ namespace async { ...@@ -30,7 +30,7 @@ namespace async {
template <typename F> template <typename F>
Async<typename FirstArgOf<F>::type::value_type> promiseWait(F&& func) { Async<typename FirstArgOf<F>::type::value_type> promiseWait(F&& func) {
// Call into blocking API // Call into blocking API
return fibers::await(std::forward<F>(func)); return fibers::await_async(std::forward<F>(func));
} }
} // namespace async } // namespace async
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment