folly icon indicating copy to clipboard operation
folly copied to clipboard

add a helper for ScopeExitTask for setting executor

Open tchaikov opened this issue 3 years ago • 0 comments

despite that ScopeExitTaskPromise<> declares ScopeExitTask as a friend, and ScopeExitTask considers co_viaIfAsync() as its friend, co_viaIfAsync() is still not a friend of ScopeExitTaskPromise<>, hence it does not have the access to its member variable of executor_, which is declared as "private". because friendship is not transitive in C++. see also https://isocpp.org/wiki/faq/friends#friendship-not-inherited-transitive

in this change, a proxy helper is added for setting the executor.

otherwise we'd have

In file included from /home/kefu/dev/folly/folly/experimental/coro/Task.h:35, from /home/kefu/dev/folly/folly/experimental/coro/AsyncScope.h:22, from /home/kefu/dev/folly/folly/experimental/coro/test/ScopeExitTest.cpp:17: folly/folly/experimental/coro/ScopeExit.h: In instantiation of ‘auto folly::coro::detail::co_viaIfAsync(folly::Executor::KeepAlive<>, folly::coro::detail::ScopeExitTask<>&&)’: folly/folly/experimental/coro/ViaIfAsync.h:475:36: required by substitution of ‘template<class Awaitable> decltype (folly::coro::detail::adl::co_viaIfAsync(std::move(executor), static_cast<Awaitable&&>(awaitable))) folly::coro::detail::adl::ViaIfAsyncFun$ folly/folly/experimental/coro/Task.h:125:69: required from ‘auto folly::coro::detail::TaskPromiseBase::await_transform(Awaitable&&) [with Awaitable = folly::coro::detail::ScopeExitTask<>]’ folly/folly/experimental/coro/test/ScopeExitTest.cpp:43:6: required from here folly/folly/experimental/coro/ScopeExit.h:173:23: error: ‘folly::Executor::KeepAlive<> folly::coro::detail::ScopeExitTaskPromiseBase::executor_’ is protected within this context 173 | t.coro_.promise().executor_ = std::move(executor); | ~~~~~~~~~~~~~~~~~~^~~~~~~~~ /home/kefu/dev/folly/folly/experimental/coro/ScopeExit.h:130:32: note: declared protected here 130 | folly::Executor::KeepAlive<> executor_; | ^~~~~~~~~

Signed-off-by: Kefu Chai [email protected]

tchaikov avatar Mar 23 '22 13:03 tchaikov