diff --git a/folly/experimental/coro/Task.h b/folly/experimental/coro/Task.h index 5ad5cd00dac5c80b1bdb1b028b2d2f53a534195f..c0d07ec3ce27913383dded73bc470d03b3173c3f 100644 --- a/folly/experimental/coro/Task.h +++ b/folly/experimental/coro/Task.h @@ -357,9 +357,10 @@ class FOLLY_NODISCARD Task { } SemiFuture<folly::lift_unit_t<StorageType>> semi() && { - return makeSemiFuture().defer( - [task = std::move(*this)](Executor* executor, Try<Unit>&&) mutable { - return std::move(task).scheduleOn(executor).start(); + return makeSemiFuture().deferExTry( + [task = std::move(*this)]( + const Executor::KeepAlive<>& executor, Try<Unit>&&) mutable { + return std::move(task).scheduleOn(executor.get()).start(); }); } diff --git a/folly/futures/Future-inl.h b/folly/futures/Future-inl.h index 44de9c45986f6cb96b24dc7e44ae41f38a64461d..31871d72492d5d547f2295fd04f656a399535455 100644 --- a/folly/futures/Future-inl.h +++ b/folly/futures/Future-inl.h @@ -903,7 +903,7 @@ template <class T> template <typename F> SemiFuture< typename futures::detail::tryExecutorCallableResult<T, F>::value_type> -SemiFuture<T>::defer(F&& func) && { +SemiFuture<T>::deferExTry(F&& func) && { DeferredExecutor* deferredExecutor = getDeferredExecutor(); if (!deferredExecutor) { auto newDeferredExecutor = DeferredExecutor::create(); diff --git a/folly/futures/Future-pre.h b/folly/futures/Future-pre.h index 6452d417d097a82d1790fa52c4c1dd625046e798..81b3aad2709afe940f2e58098cc5cfdd777c1803 100644 --- a/folly/futures/Future-pre.h +++ b/folly/futures/Future-pre.h @@ -140,7 +140,8 @@ template < typename F, typename = std::enable_if_t<is_invocable<F, Executor*, Try<T>&&>::value>> struct tryExecutorCallableResult { - typedef detail::argResult<true, F, Executor*, Try<T>&&> Arg; + typedef detail::argResult<true, F, const Executor::KeepAlive<>&, Try<T>&&> + Arg; typedef isFutureOrSemiFuture<typename Arg::Result> ReturnsFuture; typedef typename ReturnsFuture::Inner value_type; typedef Future<value_type> Return; diff --git a/folly/futures/Future.h b/folly/futures/Future.h index 2698320bc7890ad966894dee56116e4d02687444..058295ba0b9cf1dfcc94fe5c14cf8a4cfa7c19fb 100644 --- a/folly/futures/Future.h +++ b/folly/futures/Future.h @@ -686,7 +686,7 @@ class SemiFuture : private futures::detail::FutureBase<T> { template <typename F> SemiFuture< typename futures::detail::tryExecutorCallableResult<T, F>::value_type> - defer(F&& func) &&; + deferExTry(F&& func) &&; template <typename R, typename... Args> auto defer(R (&func)(Args...)) && { diff --git a/folly/futures/test/SemiFutureTest.cpp b/folly/futures/test/SemiFutureTest.cpp index d624b695e7d9b8232aa79d7363984bb59f1a72e1..4388df738e8b5617928d8c5a79fd8778846c7a5c 100644 --- a/folly/futures/test/SemiFutureTest.cpp +++ b/folly/futures/test/SemiFutureTest.cpp @@ -1172,8 +1172,10 @@ TEST(SemiFuture, DeferWithNestedSemiFuture) { TEST(SemiFuture, DeferWithExecutor) { ManualExecutor executor; - auto sf = makeSemiFuture().defer( - [&](Executor* e, Try<Unit>) { EXPECT_EQ(&executor, e); }); + auto sf = makeSemiFuture().deferExTry( + [&](const Executor::KeepAlive<>& e, Try<Unit>) { + EXPECT_EQ(&executor, e.get()); + }); std::move(sf).via(&executor).getVia(&executor); }