Commit eb5c5900 authored by Lee Howes's avatar Lee Howes Committed by Facebook Github Bot

Add result DeferredExecutor to avoid risk of double nesting

Summary: Under some circumstances the DeferredExecutor might already have nested executors and this code adds more. Both incoming futures should instead nest within a fresh DeferredExecutor returned that is part of the SemiFuture from the operation.

Reviewed By: mpark

Differential Revision: D17121117

fbshipit-source-id: b4507bf5d7b0c98e5e5de6f73ff4bd3e2790374c
parent 5db275b9
...@@ -2049,12 +2049,15 @@ SemiFuture<T> SemiFuture<T>::within(Duration dur, E e, Timekeeper* tk) && { ...@@ -2049,12 +2049,15 @@ SemiFuture<T> SemiFuture<T>::within(Duration dur, E e, Timekeeper* tk) && {
} }
}); });
// Construct the future to return, assume the deferred executor from // Construct the future to return, create a fresh DeferredExecutor and
// thisFuture and make afterFuture's executor nested to correctly propagate // nest the other two inside it, in case they already carry nested executors.
// concrete exeutors
auto fut = ctx->promise.getSemiFuture(); auto fut = ctx->promise.getSemiFuture();
fut.setExecutor(ctx->thisFuture.stealDeferredExecutor()); auto newDeferredExecutor = futures::detail::KeepAliveOrDeferred(
futures::detail::DeferredExecutor::create());
fut.setExecutor(std::move(newDeferredExecutor));
std::vector<folly::futures::detail::DeferredWrapper> nestedExecutors; std::vector<folly::futures::detail::DeferredWrapper> nestedExecutors;
nestedExecutors.emplace_back(ctx->thisFuture.stealDeferredExecutor());
nestedExecutors.emplace_back(ctx->afterFuture.stealDeferredExecutor()); nestedExecutors.emplace_back(ctx->afterFuture.stealDeferredExecutor());
futures::detail::getDeferredExecutor(fut)->setNestedExecutors( futures::detail::getDeferredExecutor(fut)->setNestedExecutors(
std::move(nestedExecutors)); std::move(nestedExecutors));
......
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