proxygen
folly::futures::detail Namespace Reference

Namespaces

 detail_msvc_15_7_workaround
 

Classes

struct  argResult
 
struct  ArgType
 
struct  ArgType< Arg, Args... >
 
struct  ArgType<>
 
struct  callableResult
 
class  Core
 
class  CoreCallbackState
 
class  DeferredExecutor
 
struct  EmptyConstruct
 
struct  Extract
 
struct  Extract< R(&)(Args...)>
 
struct  Extract< R(*)(Args...)>
 
struct  Extract< R(Class::*)(Args...) const >
 
struct  Extract< R(Class::*)(Args...)>
 
class  FutureBase
 
struct  retrying_policy_fut_tag
 
struct  retrying_policy_raw_tag
 
struct  retrying_policy_traits
 
struct  SpinLock
 SpinLock is and must stay a 1-byte object because of how Core is laid out. More...
 
struct  tryCallableResult
 
struct  TryEquals
 
struct  valueCallableResult
 
class  WaitExecutor
 
struct  WindowFakeVector
 

Typedefs

typedef folly::fibers::Baton FutureBatonType
 

Enumerations

enum  State : uint8_t {
  State::Start = 1 << 0, State::OnlyResult = 1 << 1, State::OnlyCallback = 1 << 2, State::Proxy = 1 << 3,
  State::Done = 1 << 4, State::Empty = 1 << 5
}
 See Core for details. More...
 

Functions

constexpr State operator& (State a, State b)
 
constexpr State operator| (State a, State b)
 
constexpr State operator^ (State a, State b)
 
constexpr State operator~ (State a)
 
template<typename T , typename F >
auto makeCoreCallbackState (Promise< T > &&p, F &&f) noexcept(noexcept(CoreCallbackState< T, F >(std::declval< Promise< T > && >(), std::declval< F && >())))
 
template<typename T , typename R , typename... Args>
auto makeCoreCallbackState (Promise< T > &&p, R(&f)(Args...)) noexcept
 
template<class T >
Future< TchainExecutor (Executor *, Future< T > &&f)
 
template<class T >
Future< TchainExecutor (Executor *e, SemiFuture< T > &&f)
 
template<typename V , typename... Fs, std::size_t... Is>
FOLLY_ALWAYS_INLINE FOLLY_ATTR_VISIBILITY_HIDDEN void foreach_ (index_sequence< Is... >, V &&v, Fs &&...fs)
 
template<typename V , typename... Fs>
FOLLY_ALWAYS_INLINE FOLLY_ATTR_VISIBILITY_HIDDEN void foreach (V &&v, Fs &&...fs)
 
template<typename T >
DeferredExecutorgetDeferredExecutor (SemiFuture< T > &future)
 
template<typename T >
folly::Executor::KeepAlive< DeferredExecutorstealDeferredExecutor (SemiFuture< T > &future)
 
template<typename T >
folly::Executor::KeepAlive< DeferredExecutorstealDeferredExecutor (Future< T > &)
 
template<typename... Ts>
void stealDeferredExecutorsVariadic (std::vector< folly::Executor::KeepAlive< DeferredExecutor >> &executors, Ts &...ts)
 
template<class InputIterator >
void stealDeferredExecutors (std::vector< folly::Executor::KeepAlive< DeferredExecutor >> &executors, InputIterator first, InputIterator last)
 
template<class FutureType , typename T = typename FutureType::value_type>
void waitImpl (FutureType &f)
 
template<class T >
void convertFuture (SemiFuture< T > &&sf, Future< T > &f)
 
template<class T >
void convertFuture (SemiFuture< T > &&sf, SemiFuture< T > &f)
 
template<class FutureType , typename T = typename FutureType::value_type>
void waitImpl (FutureType &f, Duration dur)
 
template<class T >
void waitViaImpl (Future< T > &f, DrivableExecutor *e)
 
template<class T , typename Rep , typename Period >
void waitViaImpl (Future< T > &f, TimedDrivableExecutor *e, const std::chrono::duration< Rep, Period > &timeout)
 
template<typename T >
void coreDetachPromiseMaybeWithResult (Core< T > &core)
 
template<class Policy , class FF , class Prom >
void retryingImpl (size_t k, Policy &&p, FF &&ff, Prom prom)
 
template<class Policy , class FF >
invoke_result_t< FF, size_t > retrying (size_t k, Policy &&p, FF &&ff)
 
template<class Policy , class FF >
invoke_result_t< FF, size_t > retrying (Policy &&p, FF &&ff, retrying_policy_raw_tag)
 
template<class Policy , class FF >
invoke_result_t< FF, size_t > retrying (Policy &&p, FF &&ff, retrying_policy_fut_tag)
 
template<class URNG >
Duration retryingJitteredExponentialBackoffDur (size_t n, Duration backoff_min, Duration backoff_max, double jitter_param, URNG &rng)
 
template<class Policy , class URNG >
std::function< Future< bool >size_t, const exception_wrapper &)> retryingPolicyCappedJitteredExponentialBackoff (size_t max_tries, Duration backoff_min, Duration backoff_max, double jitter_param, URNG &&rng, Policy &&p)
 
template<class Policy , class URNG >
std::function< Future< bool >size_t, const exception_wrapper &)> retryingPolicyCappedJitteredExponentialBackoff (size_t max_tries, Duration backoff_min, Duration backoff_max, double jitter_param, URNG &&rng, Policy &&p, retrying_policy_raw_tag)
 
template<class Policy , class URNG >
std::function< Future< bool >size_t, const exception_wrapper &)> retryingPolicyCappedJitteredExponentialBackoff (size_t max_tries, Duration backoff_min, Duration backoff_max, double jitter_param, URNG &&rng, Policy &&p, retrying_policy_fut_tag)
 

Typedef Documentation

Enumeration Type Documentation

See Core for details.

Enumerator
Start 
OnlyResult 
OnlyCallback 
Proxy 
Done 
Empty 

Definition at line 43 of file Core.h.

Function Documentation

template<class T >
Future<T> folly::futures::detail::chainExecutor ( Executor ,
Future< T > &&  f 
)

Definition at line 370 of file Future-inl.h.

References f, and folly::gen::move.

Referenced by chainExecutor().

370  {
371  return std::move(f);
372 }
auto f
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T >
void folly::futures::detail::convertFuture ( SemiFuture< T > &&  sf,
Future< T > &  f 
)

Definition at line 2026 of file Future-inl.h.

References exe, folly::futures::detail::FutureBase< T >::getExecutor(), folly::InlineExecutor::instance(), and folly::gen::move.

Referenced by folly::Future< folly::folly::Unit >::Future(), and folly::futures::detail::FutureBase< T >::setExecutor().

2026  {
2027  // Carry executor from f, inserting an inline executor if it did not have one
2028  auto* exe = f.getExecutor();
2029  f = std::move(sf).via(exe ? exe : &InlineExecutor::instance());
2030 }
auto f
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
InlineExecutor exe
Definition: Benchmark.cpp:337
template<class T >
void folly::futures::detail::convertFuture ( SemiFuture< T > &&  sf,
SemiFuture< T > &  f 
)

Definition at line 2033 of file Future-inl.h.

References folly::gen::move.

Referenced by waitImpl().

2033  {
2034  f = std::move(sf);
2035 }
auto f
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<typename T >
void folly::futures::detail::coreDetachPromiseMaybeWithResult ( Core< T > &  core)

Definition at line 30 of file Promise-inl.h.

References folly::futures::detail::Core< T >::detachPromise(), folly::futures::detail::Core< T >::hasResult(), name, folly::futures::detail::Core< T >::setResult(), and folly::T.

Referenced by folly::Promise< T >::detach().

30  {
31  if (!core.hasResult()) {
32  core.setResult(Try<T>(exception_wrapper(BrokenPromise(typeid(T).name()))));
33  }
34  core.detachPromise();
35 }
#define T(v)
Definition: http_parser.c:233
const char * name
Definition: http_parser.c:437
template<typename V , typename... Fs>
FOLLY_ALWAYS_INLINE FOLLY_ATTR_VISIBILITY_HIDDEN void folly::futures::detail::foreach ( V &&  v,
Fs &&...  fs 
)

Definition at line 1387 of file Future-inl.h.

References testing::_, foreach_(), and v.

Referenced by folly::collect(), and folly::collectAllSemiFuture().

1389  {
1390  using _ = index_sequence_for<Fs...>;
1391  foreach_(_{}, static_cast<V&&>(v), static_cast<Fs&&>(fs)...);
1392 }
make_index_sequence< sizeof...(T)> index_sequence_for
Definition: Utility.h:211
auto v
const internal::AnythingMatcher _
FOLLY_ALWAYS_INLINE FOLLY_ATTR_VISIBILITY_HIDDEN void foreach_(index_sequence< Is... >, V &&v, Fs &&...fs)
Definition: Future-inl.h:1382
template<typename V , typename... Fs, std::size_t... Is>
FOLLY_ALWAYS_INLINE FOLLY_ATTR_VISIBILITY_HIDDEN void folly::futures::detail::foreach_ ( index_sequence< Is... >  ,
V &&  v,
Fs &&...  fs 
)

Definition at line 1382 of file Future-inl.h.

References testing::_, and v.

Referenced by foreach().

1382  {
1383  using _ = int[];
1384  void(_{0, (void(v(index_constant<Is>{}, static_cast<Fs&&>(fs))), 0)...});
1385 }
auto v
const internal::AnythingMatcher _
template<typename T >
DeferredExecutor * folly::futures::detail::getDeferredExecutor ( SemiFuture< T > &  future)
template<typename T , typename F >
auto folly::futures::detail::makeCoreCallbackState ( Promise< T > &&  p,
F &&  f 
)
noexcept

Definition at line 125 of file Future-inl.h.

References testing::Args(), f, folly::gen::move, and folly::T.

Referenced by chainExecutor(), folly::Future< T >::onError(), folly::Future< T >::onTimeout(), and folly::futures::detail::FutureBase< T >::thenImplementation().

128  {
129  return CoreCallbackState<T, F>(std::move(p), std::forward<F>(f));
130 }
auto f
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<typename T , typename R , typename... Args>
auto folly::futures::detail::makeCoreCallbackState ( Promise< T > &&  p,
R(&)(Args...)  f 
)
noexcept

Definition at line 133 of file Future-inl.h.

References testing::Args(), f, folly::gen::move, and folly::T.

133  {
134  return CoreCallbackState<T, R (*)(Args...)>(std::move(p), &f);
135 }
#define T(v)
Definition: http_parser.c:233
auto f
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
constexpr State folly::futures::detail::operator& ( State  a,
State  b 
)

Definition at line 51 of file Core.h.

References uint8_t.

Referenced by Data< f, pad >::Data().

51  {
52  return State(uint8_t(a) & uint8_t(b));
53 }
char b
State
See Core for details.
Definition: Core.h:43
char a
constexpr State folly::futures::detail::operator^ ( State  a,
State  b 
)

Definition at line 57 of file Core.h.

References uint8_t.

57  {
58  return State(uint8_t(a) ^ uint8_t(b));
59 }
char b
State
See Core for details.
Definition: Core.h:43
char a
constexpr State folly::futures::detail::operator| ( State  a,
State  b 
)

Definition at line 54 of file Core.h.

References uint8_t.

54  {
55  return State(uint8_t(a) | uint8_t(b));
56 }
char b
State
See Core for details.
Definition: Core.h:43
char a
constexpr State folly::futures::detail::operator~ ( State  a)

Definition at line 60 of file Core.h.

References uint8_t.

60  {
61  return State(~uint8_t(a));
62 }
State
See Core for details.
Definition: Core.h:43
char a
template<class Policy , class FF >
invoke_result_t<FF, size_t> folly::futures::detail::retrying ( size_t  k,
Policy &&  p,
FF &&  ff 
)

Definition at line 114 of file Retrying.h.

References f, folly::gen::move, retryingImpl(), and folly::T.

Referenced by folly::futures::retrying(), and retrying().

114  {
115  using F = invoke_result_t<FF, size_t>;
116  using T = typename F::value_type;
117  auto prom = Promise<T>();
118  auto f = prom.getFuture();
119  retryingImpl(
120  k, std::forward<Policy>(p), std::forward<FF>(ff), std::move(prom));
121  return f;
122 }
#define T(v)
Definition: http_parser.c:233
auto f
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void retryingImpl(size_t k, Policy &&p, FF &&ff, Prom prom)
Definition: Retrying.h:83
KeyT k
template<class Policy , class FF >
invoke_result_t<FF, size_t> folly::futures::detail::retrying ( Policy &&  p,
FF &&  ff,
retrying_policy_raw_tag   
)

Definition at line 126 of file Retrying.h.

References k, folly::gen::move, and retrying().

126  {
127  auto q = [pm = std::forward<Policy>(p)](size_t k, exception_wrapper x) {
128  return makeFuture<bool>(pm(k, x));
129  };
130  return retrying(0, std::move(q), std::forward<FF>(ff));
131 }
Definition: InvokeTest.cpp:58
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
invoke_result_t< FF, size_t > retrying(Policy &&p, FF &&ff, retrying_policy_fut_tag)
Definition: Retrying.h:135
KeyT k
template<class Policy , class FF >
invoke_result_t<FF, size_t> folly::futures::detail::retrying ( Policy &&  p,
FF &&  ff,
retrying_policy_fut_tag   
)

Definition at line 135 of file Retrying.h.

References retrying().

135  {
136  return retrying(0, std::forward<Policy>(p), std::forward<FF>(ff));
137 }
invoke_result_t< FF, size_t > retrying(Policy &&p, FF &&ff, retrying_policy_fut_tag)
Definition: Retrying.h:135
template<class Policy , class FF , class Prom >
void folly::futures::detail::retryingImpl ( size_t  k,
Policy &&  p,
FF &&  ff,
Prom  prom 
)

Definition at line 83 of file Retrying.h.

References folly::Try< T >::exception(), f, folly::Try< T >::hasValue(), folly::makeFutureWith(), folly::gen::move, folly::pushmi::detail::t, folly::T, folly::value(), and folly::Try< T >::value().

Referenced by retrying().

83  {
84  using F = invoke_result_t<FF, size_t>;
85  using T = typename F::value_type;
86  auto f = makeFutureWith([&] { return ff(k++); });
87  std::move(f).then([k,
88  prom = std::move(prom),
89  pm = std::forward<Policy>(p),
90  ffm = std::forward<FF>(ff)](Try<T>&& t) mutable {
91  if (t.hasValue()) {
92  prom.setValue(std::move(t).value());
93  return;
94  }
95  auto& x = t.exception();
96  auto q = makeFutureWith([&] { return pm(k, x); });
97  std::move(q).then([k,
98  prom = std::move(prom),
99  xm = std::move(x),
100  pm = std::move(pm),
101  ffm = std::move(ffm)](Try<bool> shouldRetry) mutable {
102  if (shouldRetry.hasValue() && shouldRetry.value()) {
103  retryingImpl(k, std::move(pm), std::move(ffm), std::move(prom));
104  } else if (shouldRetry.hasValue()) {
105  prom.setException(std::move(xm));
106  } else {
107  prom.setException(std::move(shouldRetry.exception()));
108  }
109  });
110  });
111 }
Definition: InvokeTest.cpp:58
#define T(v)
Definition: http_parser.c:233
auto f
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void retryingImpl(size_t k, Policy &&p, FF &&ff, Prom prom)
Definition: Retrying.h:83
static const char *const value
Definition: Conv.cpp:50
KeyT k
std::enable_if< isFuture< invoke_result_t< F > >::value, invoke_result_t< F > >::type makeFutureWith(F &&func)
Definition: Future-inl.h:1322
template<class URNG >
Duration folly::futures::detail::retryingJitteredExponentialBackoffDur ( size_t  n,
Duration  backoff_min,
Duration  backoff_max,
double  jitter_param,
URNG &  rng 
)

Definition at line 141 of file Retrying.h.

References dist, max, min, and UNLIKELY.

Referenced by retryingPolicyCappedJitteredExponentialBackoff(), and TEST().

146  {
147  auto dist = std::normal_distribution<double>(0.0, jitter_param);
148  auto jitter = std::exp(dist(rng));
149  auto backoff_rep = jitter * backoff_min.count() * std::pow(2, n - 1);
150  if (UNLIKELY(backoff_rep >= std::numeric_limits<Duration::rep>::max())) {
151  return backoff_max;
152  }
153  auto backoff = Duration(Duration::rep(backoff_rep));
154  return std::max(backoff_min, std::min(backoff_max, backoff));
155 }
LogLevel max
Definition: LogLevel.cpp:31
auto rng
Definition: CollectTest.cpp:31
LogLevel min
Definition: LogLevel.cpp:30
std::uniform_int_distribution< milliseconds::rep > dist
StatsClock::duration Duration
#define UNLIKELY(x)
Definition: Likely.h:48
template<class Policy , class URNG >
std::function<Future<bool>size_t, const exception_wrapper&)> folly::futures::detail::retryingPolicyCappedJitteredExponentialBackoff ( size_t  max_tries,
Duration  backoff_min,
Duration  backoff_max,
double  jitter_param,
URNG &&  rng,
Policy &&  p 
)

Definition at line 159 of file Retrying.h.

References folly::makeFuture(), folly::gen::move, retryingJitteredExponentialBackoffDur(), rng, and folly::futures::sleep().

Referenced by retryingPolicyCappedJitteredExponentialBackoff(), folly::futures::retryingPolicyCappedJitteredExponentialBackoff(), and TEST().

165  {
166  return [pm = std::forward<Policy>(p),
167  max_tries,
168  backoff_min,
169  backoff_max,
170  jitter_param,
171  rngp = std::forward<URNG>(rng)](
172  size_t n, const exception_wrapper& ex) mutable {
173  if (n == max_tries) {
174  return makeFuture(false);
175  }
176  return pm(n, ex).then(
177  [n, backoff_min, backoff_max, jitter_param, rngp = std::move(rngp)](
178  bool v) mutable {
179  if (!v) {
180  return makeFuture(false);
181  }
183  n, backoff_min, backoff_max, jitter_param, rngp);
184  return futures::sleep(backoff).thenValue([](auto&&) { return true; });
185  });
186  };
187 }
Duration retryingJitteredExponentialBackoffDur(size_t n, Duration backoff_min, Duration backoff_max, double jitter_param, URNG &rng)
Definition: Retrying.h:141
Future< Unit > sleep(Duration dur, Timekeeper *tk)
Definition: Future.cpp:42
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
auto rng
Definition: CollectTest.cpp:31
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
template<class Policy , class URNG >
std::function<Future<bool>size_t, const exception_wrapper&)> folly::futures::detail::retryingPolicyCappedJitteredExponentialBackoff ( size_t  max_tries,
Duration  backoff_min,
Duration  backoff_max,
double  jitter_param,
URNG &&  rng,
Policy &&  p,
retrying_policy_raw_tag   
)

Definition at line 191 of file Retrying.h.

References folly::makeFuture(), folly::gen::move, retryingPolicyCappedJitteredExponentialBackoff(), and rng.

198  {
199  auto q = [pm = std::forward<Policy>(p)](
200  size_t n, const exception_wrapper& e) {
201  return makeFuture(pm(n, e));
202  };
204  max_tries,
205  backoff_min,
206  backoff_max,
207  jitter_param,
208  std::forward<URNG>(rng),
209  std::move(q));
210 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
auto rng
Definition: CollectTest.cpp:31
std::function< Future< bool >size_t, const exception_wrapper &)> retryingPolicyCappedJitteredExponentialBackoff(size_t max_tries, Duration backoff_min, Duration backoff_max, double jitter_param)
Definition: Retrying.h:265
Future< typename std::decay< T >::type > makeFuture(T &&t)
Definition: Future-inl.h:1310
template<class Policy , class URNG >
std::function<Future<bool>size_t, const exception_wrapper&)> folly::futures::detail::retryingPolicyCappedJitteredExponentialBackoff ( size_t  max_tries,
Duration  backoff_min,
Duration  backoff_max,
double  jitter_param,
URNG &&  rng,
Policy &&  p,
retrying_policy_fut_tag   
)

Definition at line 214 of file Retrying.h.

References retryingPolicyCappedJitteredExponentialBackoff(), and rng.

221  {
223  max_tries,
224  backoff_min,
225  backoff_max,
226  jitter_param,
227  std::forward<URNG>(rng),
228  std::forward<Policy>(p));
229 }
auto rng
Definition: CollectTest.cpp:31
std::function< Future< bool >size_t, const exception_wrapper &)> retryingPolicyCappedJitteredExponentialBackoff(size_t max_tries, Duration backoff_min, Duration backoff_max, double jitter_param)
Definition: Retrying.h:265
template<typename T >
folly::Executor::KeepAlive< DeferredExecutor > folly::futures::detail::stealDeferredExecutor ( SemiFuture< T > &  future)

Definition at line 1400 of file Future-inl.h.

References folly::SemiFuture< T >::stealDeferredExecutor().

Referenced by folly::SemiFuture< T >::SemiFuture(), and folly::futures::detail::FutureBase< T >::setExecutor().

1401  {
1402  return future.stealDeferredExecutor();
1403 }
template<typename T >
folly::Executor::KeepAlive<DeferredExecutor> folly::futures::detail::stealDeferredExecutor ( Future< T > &  )

Definition at line 1406 of file Future-inl.h.

Referenced by stealDeferredExecutors(), and stealDeferredExecutorsVariadic().

1406  {
1407  return {};
1408 }
template<class InputIterator >
void folly::futures::detail::stealDeferredExecutors ( std::vector< folly::Executor::KeepAlive< DeferredExecutor >> &  executors,
InputIterator  first,
InputIterator  last 
)

Definition at line 1424 of file Future-inl.h.

References folly::pushmi::executor, folly::gen::move, and stealDeferredExecutor().

Referenced by folly::collectAllSemiFuture(), and folly::collectAnyWithoutException().

1427  {
1428  for (auto it = first; it != last; ++it) {
1429  if (auto executor = stealDeferredExecutor(*it)) {
1430  executors.push_back(std::move(executor));
1431  }
1432  }
1433 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
folly::Executor::KeepAlive< DeferredExecutor > stealDeferredExecutor(Future< T > &)
Definition: Future-inl.h:1406
constexpr detail::First first
Definition: Base-inl.h:2553
template<typename... Ts>
void folly::futures::detail::stealDeferredExecutorsVariadic ( std::vector< folly::Executor::KeepAlive< DeferredExecutor >> &  executors,
Ts &...  ts 
)

Definition at line 1411 of file Future-inl.h.

References folly::pushmi::executor, folly::gen::move, stealDeferredExecutor(), and folly::unit.

Referenced by folly::collectAllSemiFuture().

1413  {
1414  auto foreach = [&](auto& future) {
1415  if (auto executor = stealDeferredExecutor(future)) {
1416  executors.push_back(std::move(executor));
1417  }
1418  return folly::unit;
1419  };
1420  [](...) {}(foreach(ts)...);
1421 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
constexpr Unit unit
Definition: Unit.h:45
folly::Executor::KeepAlive< DeferredExecutor > stealDeferredExecutor(Future< T > &)
Definition: Future-inl.h:1406
template<class FutureType , typename T = typename FutureType::value_type>
void folly::futures::detail::waitImpl ( FutureType &  f)

Definition at line 2004 of file Future-inl.h.

References convertFuture(), folly::Promise< T >::getSemiFuture(), folly::InlineExecutor::instance(), folly::gen::move, folly::Promise< T >::setTry(), folly::pushmi::detail::t, and folly::futures::detail::FutureBase< T >::value().

Referenced by folly::SemiFuture< T >::wait(), and folly::Future< T >::wait().

2004  {
2005  if (std::is_base_of<Future<T>, FutureType>::value) {
2006  f = std::move(f).via(&InlineExecutor::instance());
2007  }
2008  // short-circuit if there's nothing to do
2009  if (f.isReady()) {
2010  return;
2011  }
2012 
2013  Promise<T> promise;
2014  auto ret = promise.getSemiFuture();
2015  auto baton = std::make_shared<FutureBatonType>();
2016  f.setCallback_([baton, promise = std::move(promise)](Try<T>&& t) mutable {
2017  promise.setTry(std::move(t));
2018  baton->post();
2019  });
2020  convertFuture(std::move(ret), f);
2021  baton->wait();
2022  assert(f.isReady());
2023 }
auto f
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void convertFuture(SemiFuture< T > &&sf, SemiFuture< T > &f)
Definition: Future-inl.h:2033
static const char *const value
Definition: Conv.cpp:50
template<class FutureType , typename T = typename FutureType::value_type>
void folly::futures::detail::waitImpl ( FutureType &  f,
Duration  dur 
)

Definition at line 2038 of file Future-inl.h.

References convertFuture(), folly::Promise< T >::getSemiFuture(), folly::InlineExecutor::instance(), folly::gen::move, folly::Promise< T >::setTry(), folly::pushmi::detail::t, and folly::futures::detail::FutureBase< T >::value().

2038  {
2039  if (std::is_base_of<Future<T>, FutureType>::value) {
2040  f = std::move(f).via(&InlineExecutor::instance());
2041  }
2042  // short-circuit if there's nothing to do
2043  if (f.isReady()) {
2044  return;
2045  }
2046 
2047  Promise<T> promise;
2048  auto ret = promise.getSemiFuture();
2049  auto baton = std::make_shared<FutureBatonType>();
2050  f.setCallback_([baton, promise = std::move(promise)](Try<T>&& t) mutable {
2051  promise.setTry(std::move(t));
2052  baton->post();
2053  });
2054  convertFuture(std::move(ret), f);
2055  if (baton->try_wait_for(dur)) {
2056  assert(f.isReady());
2057  }
2058 }
auto f
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void convertFuture(SemiFuture< T > &&sf, SemiFuture< T > &f)
Definition: Future-inl.h:2033
static const char *const value
Definition: Conv.cpp:50
template<class T >
void folly::futures::detail::waitViaImpl ( Future< T > &  f,
DrivableExecutor e 
)

Definition at line 2061 of file Future-inl.h.

References folly::DrivableExecutor::drive(), folly::InlineExecutor::instance(), folly::futures::detail::FutureBase< T >::isReady(), folly::gen::move, folly::pushmi::detail::t, and folly::T.

Referenced by folly::Future< T >::waitVia().

2061  {
2062  // Set callback so to ensure that the via executor has something on it
2063  // so that once the preceding future triggers this callback, drive will
2064  // always have a callback to satisfy it
2065  if (f.isReady()) {
2066  return;
2067  }
2068  f = std::move(f).via(e).thenValue([](T&& t) { return std::move(t); });
2069  while (!f.isReady()) {
2070  e->drive();
2071  }
2072  assert(f.isReady());
2073  f = std::move(f).via(&InlineExecutor::instance());
2074 }
#define T(v)
Definition: http_parser.c:233
auto f
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T , typename Rep , typename Period >
void folly::futures::detail::waitViaImpl ( Future< T > &  f,
TimedDrivableExecutor e,
const std::chrono::duration< Rep, Period > &  timeout 
)

Definition at line 2077 of file Future-inl.h.

References folly::getKeepAliveToken(), folly::InlineExecutor::instance(), folly::futures::detail::FutureBase< T >::isReady(), folly::gen::move, now(), folly::pushmi::detail::t, folly::T, and folly::TimedDrivableExecutor::try_drive_until().

2080  {
2081  // Set callback so to ensure that the via executor has something on it
2082  // so that once the preceding future triggers this callback, drive will
2083  // always have a callback to satisfy it
2084  if (f.isReady()) {
2085  return;
2086  }
2087  // Chain operations, ensuring that the executor is kept alive for the duration
2088  f = std::move(f).via(e).thenValue(
2089  [keepAlive = getKeepAliveToken(e)](T&& t) { return std::move(t); });
2091  auto deadline = now + timeout;
2092  while (!f.isReady() && (now < deadline)) {
2093  e->try_drive_until(deadline);
2095  }
2096  assert(f.isReady() || (now >= deadline));
2097  if (f.isReady()) {
2098  f = std::move(f).via(&InlineExecutor::instance());
2099  }
2100 }
#define T(v)
Definition: http_parser.c:233
auto f
std::chrono::steady_clock::time_point now()
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Executor::KeepAlive< ExecutorT > getKeepAliveToken(ExecutorT *executor)
Definition: Executor.h:200