folly
folly copied to clipboard
why feature collect needs defer work function
Hi!There are following codes in collect function:
if (!executors.empty()) {
auto work = [](Try<typename decltype(future)::value_type>&& t) {
return std::move(t).value();
};
future = std::move(future).defer(work);
const auto& deferredExecutor = futures::detail::getDeferredExecutor(future);
deferredExecutor->setNestedExecutors(std::move(executors));
}
https://github.com/facebook/folly/blob/main/folly/futures/Future-inl.h#L1476
I have a question why add defer work function. What I think is that is same to add a then
callback while defer work function.
Normally, when Context is destructed, feature will start process, adding work function process will become ~Context -> precoess work -> feature's callback. why do we need add work func rather than processing ~Context -> feature's callback directly.