proxygen
folly::Future< T > Class Template Reference

#include <FiberManagerInternal.h>

Inheritance diagram for folly::Future< T >:
folly::futures::detail::FutureBase< T >

Public Types

typedef T value_type
 

Public Member Functions

template<class T2 = T, typename = typename std::enable_if< !isFuture<typename std::decay<T2>::type>::value && !isSemiFuture<typename std::decay<T2>::type>::value>::type>
 Future (T2 &&val)
 
template<class T2 = T>
 Future (typename std::enable_if< std::is_same< Unit, T2 >::value >::type *p=nullptr)
 
template<class... Args, typename std::enable_if< std::is_constructible< T, Args &&... >::value, int >::type = 0>
 Future (in_place_t, Args &&...args)
 
 Future (Future< T > const &)=delete
 
 Future (Future< T > &&) noexcept
 
template<class T2 , typename std::enable_if< !std::is_same< T, typename std::decay< T2 >::type >::value &&std::is_constructible< T, T2 && >::value &&std::is_convertible< T2 &&, T >::value, int >::type = 0>
 Future (Future< T2 > &&)
 
template<class T2 , typename std::enable_if< !std::is_same< T, typename std::decay< T2 >::type >::value &&std::is_constructible< T, T2 && >::value &&!std::is_convertible< T2 &&, T >::value, int >::type = 0>
 Future (Future< T2 > &&)
 
template<class T2 , typename std::enable_if< !std::is_same< T, typename std::decay< T2 >::type >::value &&std::is_constructible< T, T2 && >::value, int >::type = 0>
Futureoperator= (Future< T2 > &&)
 
Futureoperator= (Future const &)=delete
 
Futureoperator= (Future &&) noexcept
 
T getVia (DrivableExecutor *e)
 
T getVia (TimedDrivableExecutor *e, Duration dur)
 
Try< T > & getTryVia (DrivableExecutor *e)
 
Try< T > & getTryVia (TimedDrivableExecutor *e, Duration dur)
 
template<class F = T>
std::enable_if< isFuture< F >::value, Future< typename isFuture< T >::Inner > >::type unwrap ()&&
 
Future< Tvia (Executor *executor, int8_t priority=Executor::MID_PRI)&&
 
Future< Tvia (Executor::KeepAlive<> executor, int8_t priority=Executor::MID_PRI)&&
 
Future< Tvia (Executor *executor, int8_t priority=Executor::MID_PRI)&
 
Future< Tvia (Executor::KeepAlive<> executor, int8_t priority=Executor::MID_PRI)&
 
template<typename F , typename R = futures::detail::callableResult<T, F>>
std::enable_if< !is_invocable< F >::value &&is_invocable< F, T && >::value, typename R::Return >::type then (F &&func)&&
 
template<typename F , typename R = futures::detail::callableResult<T, F>>
std::enable_if< !is_invocable< F, T && >::value &&!is_invocable< F >::value, typename R::Return >::type then (F &&func)&&
 
template<typename F , typename R = futures::detail::callableResult<T, F>>
std::enable_if< is_invocable< F >::value, typename R::Return >::type then (F &&func)&&=delete
 
template<typename F , typename R = futures::detail::callableResult<T, F>>
R::Return then (F &&func)&=delete
 
template<typename R , typename Caller , typename... Args>
Future< typename isFuture< R >::Inner > then (R(Caller::*func)(Args...), Caller *instance)&&
 
template<typename R , typename Caller , typename... Args>
Future< typename isFuture< R >::Inner > then (R(Caller::*func)(Args...), Caller *instance)&=delete
 
template<class Arg >
auto then (Executor *x, Arg &&arg)&&
 
template<class R , class Caller , class... Args>
auto then (Executor *x, R(Caller::*func)(Args...), Caller *instance)&&
 
template<class Arg , class... Args>
auto then (Executor *x, Arg &&arg, Args &&...args)&=delete
 
template<typename F >
Future< typename futures::detail::tryCallableResult< T, F >::value_typethenTry (F &&func)&&
 
template<typename R , typename... Args>
auto thenTry (R(&func)(Args...))&&
 
template<typename F >
Future< typename futures::detail::valueCallableResult< T, F >::value_typethenValue (F &&func)&&
 
template<typename R , typename... Args>
auto thenValue (R(&func)(Args...))&&
 
template<class ExceptionType , class F >
Future< TthenError (F &&func)&&
 
template<class ExceptionType , class R , class... Args>
Future< TthenError (R(&func)(Args...))&&
 
template<class F >
Future< TthenError (F &&func)&&
 
template<class R , class... Args>
Future< TthenError (R(&func)(Args...))&&
 
Future< Unitthen ()&&
 
Future< Unitthen ()&=delete
 
Future< Unitunit ()&&
 
template<class F >
std::enable_if< !is_invocable< F, exception_wrapper >::value &&!futures::detail::Extract< F >::ReturnsFuture::value, Future< T > >::type onError (F &&func)&&
 
template<class F >
std::enable_if< !is_invocable< F, exception_wrapper >::value &&futures::detail::Extract< F >::ReturnsFuture::value, Future< T > >::type onError (F &&func)&&
 
template<class F >
std::enable_if< is_invocable< F, exception_wrapper >::value &&futures::detail::Extract< F >::ReturnsFuture::value, Future< T > >::type onError (F &&func)&&
 
template<class F >
std::enable_if< is_invocable< F, exception_wrapper >::value &&!futures::detail::Extract< F >::ReturnsFuture::value, Future< T > >::type onError (F &&func)&&
 
template<class F >
Future< TonError (F &&func)&
 
template<class F >
Future< Tensure (F &&func)&&
 
template<class F >
Future< TonTimeout (Duration, F &&func, Timekeeper *=nullptr)&&
 
Future< Twithin (Duration dur, Timekeeper *tk=nullptr)&&
 
template<class E >
Future< Twithin (Duration dur, E exception, Timekeeper *tk=nullptr)&&
 
Future< Tdelayed (Duration, Timekeeper *=nullptr)&&
 
Future< TdelayedUnsafe (Duration, Timekeeper *=nullptr)
 
T get ()&&
 
T get ()&=delete
 
T get (Duration dur)&&
 
T get (Duration dur)&=delete
 
Try< T > & getTry ()
 
Future< T > & wait ()&
 
Future< T > && wait ()&&
 
Future< T > & wait (Duration dur)&
 
Future< T > && wait (Duration dur)&&
 
Future< T > & waitVia (DrivableExecutor *e)&
 
Future< T > && waitVia (DrivableExecutor *e)&&
 
Future< T > & waitVia (TimedDrivableExecutor *e, Duration dur)&
 
Future< T > && waitVia (TimedDrivableExecutor *e, Duration dur)&&
 
Future< bool > willEqual (Future< T > &)
 
template<class F >
Future< Tfilter (F &&predicate)&&
 
template<class I , class F >
Future< I > reduce (I &&initial, F &&func)&&
 
template<class Callback , class... Callbacks>
auto thenMulti (Callback &&fn, Callbacks &&...fns)&&
 
template<class Callback >
auto thenMulti (Callback &&fn)&&
 
template<class Callback >
auto thenMulti (Callback &&fn)&
 
template<class Callback , class... Callbacks>
auto thenMultiWithExecutor (Executor *x, Callback &&fn, Callbacks &&...fns)&&
 
template<class Callback >
auto thenMultiWithExecutor (Executor *x, Callback &&fn)&&
 
SemiFuture< Tsemi ()&&
 
template<class T2 , typename std::enable_if< !std::is_same< T, typename std::decay< T2 >::type >::value &&std::is_constructible< T, T2 && >::value, int >::type >
Future< T > & operator= (Future< T2 > &&other)
 

Static Public Member Functions

static Future< TmakeEmpty ()
 

Protected Types

using Core = futures::detail::Core< T >
 

Protected Member Functions

 Future (Core *obj)
 
 Future (futures::detail::EmptyConstruct) noexcept
 

Private Types

using Base = futures::detail::FutureBase< T >
 
- Private Types inherited from folly::futures::detail::FutureBase< T >
typedef T value_type
 
using Core = futures::detail::Core< T >
 

Friends

class Promise< T >
 
template<class >
class futures::detail::FutureBase
 
template<class >
class Future
 
template<class >
class SemiFuture
 
template<class >
class FutureSplitter
 
template<class T2 >
Future< T2makeFuture (Try< T2 >)
 
template<class F >
Future< Unittimes (int n, F &&thunk)
 
template<class F >
Future< Unitwhen (bool p, F &&thunk)
 
template<class P , class F >
Future< UnitwhileDo (P &&predicate, F &&thunk)
 
template<class FT >
void futures::detail::convertFuture (SemiFuture< FT > &&sf, Future< FT > &f)
 

Additional Inherited Members

- Private Member Functions inherited from folly::futures::detail::FutureBase< T >
template<class T2 = T, typename = typename std::enable_if< !isFuture<typename std::decay<T2>::type>::value && !isSemiFuture<typename std::decay<T2>::type>::value>::type>
 FutureBase (T2 &&val)
 
template<class T2 = T>
 FutureBase (typename std::enable_if< std::is_same< Unit, T2 >::value >::type *)
 
template<class... Args, typename std::enable_if< std::is_constructible< T, Args &&... >::value, int >::type = 0>
 FutureBase (in_place_t, Args &&...args)
 
 FutureBase (FutureBase< T > const &)=delete
 
 FutureBase (SemiFuture< T > &&) noexcept
 
 FutureBase (Future< T > &&) noexcept
 
 FutureBase (Future< T > const &)=delete
 
 FutureBase (SemiFuture< T > const &)=delete
 
 ~FutureBase ()
 
bool valid () const noexcept
 
Tvalue ()&
 
T const & value () const &
 
T && value ()&&
 
T const && value () const &&
 
Try< T > & result ()&
 
Try< T > const & result () const &
 
Try< T > && result ()&&
 
Try< T > const && result () const &&
 
bool isReady () const
 
bool hasValue () const
 
bool hasException () const
 
Optional< Try< T > > poll ()
 
template<class F >
void setCallback_ (F &&func)
 
template<class F >
void setCallback_ (F &&func, std::shared_ptr< folly::RequestContext > context)
 
void raise (exception_wrapper interrupt)
 
template<class E >
void raise (E &&exception)
 
void cancel ()
 
int8_t getPriority () const
 
CoregetCore ()
 
Core const & getCore () const
 
Try< T > & getCoreTryChecked ()
 
Try< T > const & getCoreTryChecked () const
 
 FutureBase (Core *obj)
 
 FutureBase (futures::detail::EmptyConstruct) noexcept
 
void detach ()
 
void throwIfInvalid () const
 
void throwIfContinued () const
 
void assign (FutureBase< T > &&other) noexcept
 
ExecutorgetExecutor () const
 
void setExecutor (Executor *x, int8_t priority=Executor::MID_PRI)
 
void setExecutor (Executor::KeepAlive<> x, int8_t priority=Executor::MID_PRI)
 
template<typename F , typename R >
std::enable_if<!R::ReturnsFuture::value, typename R::Return >::type thenImplementation (F &&func, R)
 
template<typename F , typename R >
std::enable_if< R::ReturnsFuture::value, typename R::Return >::type thenImplementation (F &&func, R)
 
template<typename E >
SemiFuture< TwithinImplementation (Duration dur, E e, Timekeeper *tk)&&
 
- Static Private Member Functions inherited from folly::futures::detail::FutureBase< T >
template<typename Self >
static decltype(auto) getCoreImpl (Self &self)
 
template<typename Self >
static decltype(auto) getCoreTryChecked (Self &self)
 
- Private Attributes inherited from folly::futures::detail::FutureBase< T >
Corecore_
 

Detailed Description

template<class T>
class folly::Future< T >

The interface (along with SemiFuture) for the consumer-side of a producer/consumer pair.

Future vs. SemiFuture:

  • The consumer-side should generally start with a SemiFuture, not a Future.
  • Example, when a library creates and returns a future, it should usually return a SemiFuture, not a Future.
  • Reason: so the thread policy for continuations (.thenValue, etc.) can be specified by the library's caller (using .via()).
  • A SemiFuture is converted to a Future using .via().
  • Use makePromiseContract() when creating both a Promise and an associated SemiFuture/Future.

When practical, prefer SemiFuture/Future's nonblocking style/pattern:

  • the nonblocking style uses continuations, e.g., .thenValue, etc.; the continuations are deferred until the result is available.
  • the blocking style blocks until complete, e.g., .wait(), .get(), etc.
  • the two styles cannot be mixed within the same future; use one or the other.

SemiFuture/Future also provide a back-channel so an interrupt can be sent from consumer to producer; see SemiFuture/Future's raise() and Promise's setInterruptHandler().

The consumer-side SemiFuture/Future objects should generally be accessed via a single thread. That thread is referred to as the 'consumer thread.'

Definition at line 46 of file FiberManagerInternal.h.

Member Typedef Documentation

template<class T>
using folly::Future< T >::Base = futures::detail::FutureBase<T>
private

Definition at line 962 of file Future.h.

template<class T>
using folly::futures::detail::FutureBase< T >::Core = futures::detail::Core<T>
protected

Definition at line 359 of file Future.h.

template<class T>
typedef T folly::futures::detail::FutureBase< T >::value_type

Definition at line 117 of file Future.h.

Constructor & Destructor Documentation

template<class T>
template<class T2 = T, typename = typename std::enable_if< !isFuture<typename std::decay<T2>::type>::value && !isSemiFuture<typename std::decay<T2>::type>::value>::type>
folly::Future< T >::Future ( T2 &&  val)
inline

Construct a Future from a value (perfect forwarding)

Postconditions:

Definition at line 981 of file Future.h.

981 : Base(std::forward<T2>(val)) {}
futures::detail::FutureBase< T > Base
Definition: Future.h:962
template<class T>
template<class T2 = T>
folly::Future< T >::Future ( typename std::enable_if< std::is_same< Unit, T2 >::value >::type p = nullptr)
inline

Construct a (logical) Future-of-void.

Postconditions:

Definition at line 991 of file Future.h.

993  : Base(p) {}
futures::detail::FutureBase< T > Base
Definition: Future.h:962
template<class T>
template<class... Args, typename std::enable_if< std::is_constructible< T, Args &&... >::value, int >::type = 0>
folly::Future< T >::Future ( in_place_t  ,
Args &&...  args 
)
inlineexplicit

Construct a Future from a T constructed from args

Postconditions:

Definition at line 1008 of file Future.h.

1009  : Base(in_place, std::forward<Args>(args)...) {}
in_place_tag in_place(in_place_tag={})
Definition: Utility.h:235
futures::detail::FutureBase< T > Base
Definition: Future.h:962
template<class T>
folly::Future< T >::Future ( Future< T > const &  )
delete
template<class T>
folly::Future< T >::Future ( Future< T > &&  other)
noexcept

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

957  : futures::detail::FutureBase<T>(std::move(other)) {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T >
template<class T2, typename std::enable_if< !std::is_same< T, typename std::decay< T2 >::type >::value &&std::is_constructible< T, T2 && >::value &&!std::is_convertible< T2 &&, T >::value, int >::type >
folly::Future< T >::Future ( Future< T2 > &&  other)

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

References folly::Future< T >::Future, folly::gen::move, folly::T, folly::Future< T >::thenValue(), type, value, and folly::futures::detail::FutureBase< T >::value().

974  : Future(
975  std::move(other).thenValue([](T2&& v) { return T(std::move(v)); })) {}
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::std T
friend class Future
Definition: Future.h:1933
Future< typename futures::detail::valueCallableResult< T, F >::value_type > thenValue(F &&func)&&
Definition: Future-inl.h:1079
template<class T>
template<class T2 , typename std::enable_if< !std::is_same< T, typename std::decay< T2 >::type >::value &&std::is_constructible< T, T2 && >::value &&!std::is_convertible< T2 &&, T >::value, int >::type = 0>
folly::Future< T >::Future ( Future< T2 > &&  )
explicit
template<class T>
folly::Future< T >::Future ( Core obj)
inlineexplicitprotected

Definition at line 1944 of file Future.h.

1944 : Base(obj) {}
futures::detail::FutureBase< T > Base
Definition: Future.h:962
template<class T>
folly::Future< T >::Future ( futures::detail::EmptyConstruct  )
inlineexplicitprotectednoexcept

Definition at line 1946 of file Future.h.

1947  : Base(futures::detail::EmptyConstruct{}) {}
futures::detail::FutureBase< T > Base
Definition: Future.h:962

Member Function Documentation

template<class T >
Future< T > folly::Future< T >::delayed ( Duration  dur,
Timekeeper tk = nullptr 
)

Delay the completion of this Future for at least this duration from now. The optional Timekeeper is as with futures::sleep().

Preconditions:

Postconditions:

  • valid() == false
  • RESULT.valid() == true

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

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

1986  {
1987  auto e = this->getExecutor();
1988  return collectAllSemiFuture(*this, futures::sleep(dur, tk))
1989  .via(e ? e : &InlineExecutor::instance())
1990  .thenValue([](std::tuple<Try<T>, Try<Unit>>&& tup) {
1991  return makeFuture<T>(std::get<0>(std::move(tup)));
1992  });
1993 }
Future< Unit > sleep(Duration dur, Timekeeper *tk)
Definition: Future.cpp:42
Executor * getExecutor() const
Definition: Future.h:412
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
SemiFuture< std::tuple< Try< typename remove_cvref_t< Fs >::value_type >... > > collectAllSemiFuture(Fs &&...fs)
Definition: Future-inl.h:1441
FOLLY_ATTR_VISIBILITY_HIDDEN static FOLLY_ALWAYS_INLINE InlineExecutor & instance() noexcept
template<class T >
Future< T > folly::Future< T >::delayedUnsafe ( Duration  dur,
Timekeeper tk = nullptr 
)

Delay the completion of this Future for at least this duration from now. The optional Timekeeper is as with futures::sleep(). NOTE: Deprecated WARNING: Returned future may complete on Timekeeper thread.

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

References folly::gen::move.

1996  {
1997  return std::move(*this).semi().delayed(dur, tk).toUnsafeFuture();
1998 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T >
template<class F >
Future< T > folly::Future< T >::ensure ( F &&  func)

func is like std::function<void()> and is executed unconditionally, and the value/exception is passed through to the resulting Future. func shouldn't throw, but if it does it will be captured and propagated, and discard any value/exception that this Future has obtained.

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true

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

References folly::gen::move, and folly::pushmi::detail::t.

1203  {
1204  return std::move(*this).thenTry(
1205  [funcw = std::forward<F>(func)](Try<T>&& t) mutable {
1206  std::forward<F>(funcw)();
1207  return makeFuture(std::move(t));
1208  });
1209 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T >
template<class F >
Future< T > folly::Future< T >::filter ( F &&  predicate)

predicate behaves like std::function<bool(T const&)> If the predicate does not obtain with the value, the result is a folly::FuturePredicateDoesNotObtain exception

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true

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

References folly::gen::move, folly::T, and val.

2319  {
2320  return std::move(*this).thenValue([p = std::forward<F>(predicate)](T val) {
2321  T const& valConstRef = val;
2322  if (!p(valConstRef)) {
2323  throw_exception<FuturePredicateDoesNotObtain>();
2324  }
2325  return val;
2326  });
2327 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
double val
Definition: String.cpp:273
folly::std T
template<class T >
T folly::Future< T >::get ( )

Blocks until the future is fulfilled. Returns the value (moved-out), or throws the exception. The future must not already have a continuation.

Preconditions:

Postconditions:

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

References folly::copy(), folly::gen::move, and folly::Future< T >::wait().

2245  {
2246  wait();
2247  return copy(std::move(*this)).value();
2248 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Future< T > & wait()&
Definition: Future-inl.h:2197
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
Definition: Utility.h:72
template<class T>
T folly::Future< T >::get ( )
delete
template<class T >
T folly::Future< T >::get ( Duration  dur)

Blocks until the future is fulfilled, or until dur elapses. Returns the value (moved-out), or throws the exception (which might be a FutureTimeout exception).

Preconditions:

Postconditions:

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

References folly::copy(), folly::gen::move, and folly::Future< T >::wait().

2251  {
2252  wait(dur);
2253  auto future = copy(std::move(*this));
2254  if (!future.isReady()) {
2255  throw_exception<FutureTimeout>();
2256  }
2257  return std::move(future).value();
2258 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Future< T > & wait()&
Definition: Future-inl.h:2197
constexpr std::decay< T >::type copy(T &&value) noexcept(noexcept(typename std::decay< T >::type(std::forward< T >(value))))
Definition: Utility.h:72
template<class T>
T folly::Future< T >::get ( Duration  dur)
delete
template<class T >
Try< T > & folly::Future< T >::getTry ( )

A reference to the Try of the value

Preconditions:

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

References folly::futures::detail::FutureBase< T >::result().

Referenced by folly::SemiFuture< T >::getTry().

2261  {
2262  return result();
2263 }
template<class T >
Try< T > & folly::Future< T >::getTryVia ( DrivableExecutor e)

Call e->drive() repeatedly until the future is fulfilled. Examples of DrivableExecutor include EventBase and ManualExecutor. Returns a reference to the Try of the value.

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

References folly::Future< T >::waitVia().

2280  {
2281  return waitVia(e).getTry();
2282 }
Future< T > & waitVia(DrivableExecutor *e)&
Definition: Future-inl.h:2221
template<class T >
Try< T > & folly::Future< T >::getTryVia ( TimedDrivableExecutor e,
Duration  dur 
)

getTryVia but will wait only until dur elapses. Returns the Try of the value (moved-out) or may throw a FutureTimeout exception.

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

References folly::futures::detail::FutureBase< T >::isReady(), folly::futures::detail::FutureBase< T >::result(), and folly::Future< T >::waitVia().

2285  {
2286  waitVia(e, dur);
2287  if (!this->isReady()) {
2288  throw_exception<FutureTimeout>();
2289  }
2290  return result();
2291 }
Future< T > & waitVia(DrivableExecutor *e)&
Definition: Future-inl.h:2221
template<class T >
T folly::Future< T >::getVia ( DrivableExecutor e)

Call e->drive() repeatedly until the future is fulfilled.

Examples of DrivableExecutor include EventBase and ManualExecutor.

Returns the fulfilled value (moved-out) or throws the fulfilled exception.

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

References folly::gen::move, folly::futures::detail::FutureBase< T >::value(), and folly::Future< T >::waitVia().

2266  {
2267  return std::move(waitVia(e).value());
2268 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Future< T > & waitVia(DrivableExecutor *e)&
Definition: Future-inl.h:2221
template<class T >
T folly::Future< T >::getVia ( TimedDrivableExecutor e,
Duration  dur 
)

Call e->drive() repeatedly until the future is fulfilled, or dur elapses.

Returns the fulfilled value (moved-out), throws the fulfilled exception, or on timeout throws FutureTimeout.

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

References folly::futures::detail::FutureBase< T >::isReady(), folly::gen::move, folly::futures::detail::FutureBase< T >::value(), and folly::Future< T >::waitVia().

2271  {
2272  waitVia(e, dur);
2273  if (!this->isReady()) {
2274  throw_exception<FutureTimeout>();
2275  }
2276  return std::move(value());
2277 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
Future< T > & waitVia(DrivableExecutor *e)&
Definition: Future-inl.h:2221
template<class T >
Future< T > folly::Future< T >::makeEmpty ( )
static

Creates/returns an invalid Future, that is, one with no shared state.

Postcondition:

  • RESULT.valid() == false

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

Referenced by TEST().

951  {
952  return Future<T>(futures::detail::EmptyConstruct{});
953 }
template<class T >
template<class F >
std::enable_if< is_invocable< F, exception_wrapper >::value &&!futures::detail::Extract< F >::ReturnsFuture::value, Future< T > >::type folly::Future< T >::onError ( F &&  func)

Set an error continuation for this Future. The continuation should take an argument of the type that you want to catch, and should return a value of the same type as this Future, or a Future of that type (see overload below).

Example:

makeFuture() .thenValue([] { throw std::runtime_error("oh no!"); return 42; }) .thenError<std::runtime_error>([] (std::runtime_error& e) { LOG(INFO) << "std::runtime_error: " << e.what(); return -1; // or makeFuture<int>(-1) });

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true

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

References folly::Promise< T >::core_, folly::futures::detail::FutureBase< T >::getCore(), folly::Promise< T >::getSemiFuture(), folly::InlineExecutor::instance(), folly::futures::detail::makeCoreCallbackState(), folly::gen::move, folly::futures::detail::FutureBase< T >::setCallback_(), folly::futures::detail::Core< T >::setInterruptHandlerNoLock(), folly::pushmi::detail::t, folly::T, type, and folly::futures::detail::FutureBase< T >::value().

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

1131  {
1132  typedef std::remove_reference_t<
1133  typename futures::detail::Extract<F>::FirstArg>
1134  Exn;
1135  static_assert(
1136  std::is_same<typename futures::detail::Extract<F>::RawReturn, T>::value,
1137  "Return type of onError callback must be T or Future<T>");
1138 
1139  Promise<T> p;
1140  p.core_->setInterruptHandlerNoLock(this->getCore().getInterruptHandler());
1141  auto sf = p.getSemiFuture();
1142 
1143  this->setCallback_(
1145  std::move(p), std::forward<F>(func))](Try<T>&& t) mutable {
1146  if (auto e = t.template tryGetExceptionObject<Exn>()) {
1147  state.setTry(makeTryWith([&] { return state.invoke(*e); }));
1148  } else {
1149  state.setTry(std::move(t));
1150  }
1151  });
1152 
1153  // Allow for applying to future with null executor while this is still
1154  // possible.
1155  // TODO(T26801487): Should have an executor
1156  return std::move(sf).via(&InlineExecutor::instance());
1157 }
friend class Promise< T >
Definition: Future.h:1929
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
auto makeCoreCallbackState(Promise< T > &&p, F &&f) noexcept(noexcept(CoreCallbackState< T, F >(std::declval< Promise< T > && >(), std::declval< F && >())))
Definition: Future-inl.h:125
folly::std T
FOLLY_ATTR_VISIBILITY_HIDDEN static FOLLY_ALWAYS_INLINE InlineExecutor & instance() noexcept
state
Definition: http_parser.c:272
template<class T>
template<class F >
std::enable_if< !is_invocable<F, exception_wrapper>::value && futures::detail::Extract<F>::ReturnsFuture::value, Future<T> >::type folly::Future< T >::onError ( F &&  func)

Overload of onError where the error continuation returns a Future<T>

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true
template<class T>
template<class F >
std::enable_if< is_invocable<F, exception_wrapper>::value && futures::detail::Extract<F>::ReturnsFuture::value, Future<T> >::type folly::Future< T >::onError ( F &&  func)

Overload of onError that takes exception_wrapper and returns Future<T>

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true
template<class T>
template<class F >
std::enable_if< is_invocable<F, exception_wrapper>::value && !futures::detail::Extract<F>::ReturnsFuture::value, Future<T> >::type folly::Future< T >::onError ( F &&  func)

Overload of onError that takes exception_wrapper and returns T

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true
template<class T>
template<class F >
Future<T> folly::Future< T >::onError ( F &&  func)
inline

Definition at line 1525 of file Future.h.

1525  {
1526  return std::move(*this).onError(std::forward<F>(func));
1527  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T >
template<class F >
Future< T > folly::Future< T >::onTimeout ( Duration  dur,
F &&  func,
Timekeeper tk = nullptr 
)

Like onError, but for timeouts. example:

Future<int> f = makeFuture<int>(42) .delayed(long_time) .onTimeout(short_time, [] { return -1; });

or perhaps

Future<int> f = makeFuture<int>(42) .delayed(long_time) .onTimeout(short_time, [] { return makeFuture<int>(some_exception); });

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true

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

References folly::Try< T >::exception(), folly::Promise< T >::getSemiFuture(), folly::Try< T >::hasException(), folly::InlineExecutor::instance(), folly::futures::detail::makeCoreCallbackState(), folly::makeTryWith(), folly::gen::move, folly::Future< T >::onError(), folly::futures::detail::FutureBase< T >::setCallback_(), folly::Promise< T >::setTry(), folly::pushmi::detail::t, type, and folly::futures::detail::FutureBase< T >::value().

1213  {
1214  return std::move(*this).within(dur, tk).template thenError<FutureTimeout>(
1215  [funcw = std::forward<F>(func)](auto const&) mutable {
1216  return std::forward<F>(funcw)();
1217  });
1218 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T>
template<class T2 , typename std::enable_if< !std::is_same< T, typename std::decay< T2 >::type >::value &&std::is_constructible< T, T2 && >::value, int >::type >
Future<T>& folly::Future< T >::operator= ( Future< T2 > &&  other)

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

References folly::gen::move, folly::Future< T >::operator=(), folly::T, folly::Future< T >::thenValue(), type, and value.

996  {
997  return operator=(
998  std::move(other).thenValue([](T2&& v) { return T(std::move(v)); }));
999 }
Future & operator=(Future< T2 > &&)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::std T
Future< typename futures::detail::valueCallableResult< T, F >::value_type > thenValue(F &&func)&&
Definition: Future-inl.h:1079
template<class T>
template<class T2 , typename std::enable_if< !std::is_same< T, typename std::decay< T2 >::type >::value &&std::is_constructible< T, T2 && >::value, int >::type = 0>
Future& folly::Future< T >::operator= ( Future< T2 > &&  )
template<class T>
Future& folly::Future< T >::operator= ( Future< T > const &  )
delete
template<class T >
Future< T > & folly::Future< T >::operator= ( Future< T > &&  other)
noexcept

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

References folly::futures::detail::FutureBase< T >::assign(), folly::gen::move, type, value, and folly::futures::detail::FutureBase< T >::value().

960  {
961  this->assign(std::move(other));
962  return *this;
963 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void assign(FutureBase< T > &&other) noexcept
Definition: Future-inl.h:167
template<class T >
template<class I , class F >
Future< I > folly::Future< T >::reduce ( I &&  initial,
F &&  func 
)

Like reduce, but works on a Future<std::vector<T / Try<T>>>, for example the result of collect or collectAll

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true

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

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

1865  {
1866  return std::move(*this).thenValue(
1867  [minitial = std::forward<I>(initial),
1868  mfunc = std::forward<F>(func)](T&& vals) mutable {
1869  auto ret = std::move(minitial);
1870  for (auto& val : vals) {
1871  ret = mfunc(std::move(ret), std::move(val));
1872  }
1873  return ret;
1874  });
1875 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::std T
template<class T>
SemiFuture<T> folly::Future< T >::semi ( )
inline

Moves-out *this, creating/returning a corresponding SemiFuture. Result will behave like *this except result won't have an Executor.

Postconditions:

  • RESULT.valid() == the original value of this->valid()
  • RESULT will not have an Executor regardless of whether *this had one

Definition at line 1912 of file Future.h.

1912  {
1913  return SemiFuture<T>{std::move(*this)};
1914  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T>
template<typename F , typename R = futures::detail::callableResult<T, F>>
std::enable_if< !is_invocable<F>::value && is_invocable<F, T&&>::value, typename R::Return>::type folly::Future< T >::then ( F &&  func)
inline

When this Future has completed, execute func which is a function that can be called with either T&& or Try<T>&&.

Func shall return either another Future or a value.

A Future for the return type of func is returned.

Future<string> f2 = f1.thenTry([](Try<T>&&) { return string("foo"); });

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true NOTE: All three of these variations are deprecated and deprecation attributes will be added in the near future. Please prefer thenValue, thenTry or thenError rather than then and onError as they avoid ambiguity when using polymorphic lambdas.

Definition at line 1166 of file Future.h.

1166  {
1167  return std::move(*this).thenValue(std::forward<F>(func));
1168  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T>
template<typename F , typename R = futures::detail::callableResult<T, F>>
std::enable_if< !is_invocable<F, T&&>::value && !is_invocable<F>::value, typename R::Return>::type folly::Future< T >::then ( F &&  func)
inline

Definition at line 1174 of file Future.h.

1174  {
1175  return std::move(*this).thenTry(std::forward<F>(func));
1176  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T>
template<typename F , typename R = futures::detail::callableResult<T, F>>
std::enable_if<is_invocable<F>::value, typename R::Return>::type folly::Future< T >::then ( F &&  func)
delete
template<class T>
template<typename F , typename R = futures::detail::callableResult<T, F>>
R::Return folly::Future< T >::then ( F &&  func)
delete
template<typename T >
template<typename R , typename Caller , typename... Args>
Future< typename isFuture< R >::Inner > folly::Future< T >::then ( R(Caller::*)(Args...)  func,
Caller *  instance 
)

Variant where func is an member function

struct Worker { R doWork(Try<T>); }

Worker *w; Future<R> f2 = f1.thenTry(&Worker::doWork, w);

This is just sugar for

f1.thenTry(std::bind(&Worker::doWork, w));

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true

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

References testing::Args(), folly::gen::move, folly::pushmi::detail::t, and type.

1055  {
1056  typedef typename std::remove_cv<typename std::remove_reference<
1057  typename futures::detail::ArgType<Args...>::FirstArg>::type>::type
1058  FirstArg;
1059 
1060  return std::move(*this).thenTry([instance, func](Try<T>&& t) {
1061  return (instance->*func)(t.template get<isTry<FirstArg>::value, Args>()...);
1062  });
1063 }
PskType type
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
internal::ArgsMatcher< InnerMatcher > Args(const InnerMatcher &matcher)
template<class T>
template<typename R , typename Caller , typename... Args>
Future<typename isFuture<R>::Inner> folly::Future< T >::then ( R(Caller::*)(Args...)  func,
Caller *  instance 
)
delete
template<class T>
template<class Arg >
auto folly::Future< T >::then ( Executor x,
Arg &&  arg 
)
inline

Execute the callback via the given Executor. The executor doesn't stick.

Contrast

f.via(x).then(b).then(c)

with

f.then(x, b).then(c)

In the former both b and c execute via x. In the latter, only b executes via x, and c executes via the same executor (if any) that f had.

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true

Definition at line 1247 of file Future.h.

1247  {
1248  auto oldX = this->getExecutor();
1249  this->setExecutor(x);
1250 
1251  // TODO(T29171940): thenImplementation here is ambiguous
1252  // as then used to be but that is better than keeping then in the public
1253  // API.
1254  using R = futures::detail::callableResult<T, Arg&&>;
1255  return std::move(*this)
1256  .thenImplementation(std::forward<Arg>(arg), R{})
1257  .via(oldX);
1258  }
Future< T > via(Executor *executor, int8_t priority=Executor::MID_PRI)&&
Definition: Future-inl.h:1024
Definition: InvokeTest.cpp:58
Executor * getExecutor() const
Definition: Future.h:412
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void setExecutor(Executor *x, int8_t priority=Executor::MID_PRI)
Definition: Future.h:420
template<class T>
template<class R , class Caller , class... Args>
auto folly::Future< T >::then ( Executor x,
R(Caller::*)(Args...)  func,
Caller *  instance 
)
inline

Definition at line 1261 of file Future.h.

1261  {
1262  auto oldX = this->getExecutor();
1263  this->setExecutor(x);
1264 
1265  return std::move(*this).then(func, instance).via(oldX);
1266  }
Definition: InvokeTest.cpp:58
Executor * getExecutor() const
Definition: Future.h:412
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void setExecutor(Executor *x, int8_t priority=Executor::MID_PRI)
Definition: Future.h:420
template<class T>
template<class Arg , class... Args>
auto folly::Future< T >::then ( Executor x,
Arg &&  arg,
Args &&...  args 
)
delete
template<class T >
Future< Unit > folly::Future< T >::then ( )

Convenience method for ignoring the value and creating a Future<Unit>. Exceptions still propagate. This function is identical to .unit().

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true

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

References folly::gen::move, folly::T, and type.

1120  {
1121  return std::move(*this).thenValue([](T&&) {});
1122 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::std T
template<class T>
Future<Unit> folly::Future< T >::then ( )
delete
template<class T >
template<class ExceptionType , class F >
Future< T > folly::Future< T >::thenError ( F &&  func)

Set an error continuation for this Future where the continuation can be called with a known exception type and returns a T, Future<T>, or SemiFuture<T>.

Example:

makeFuture() .thenTry([] { throw std::runtime_error("oh no!"); return 42; }) .thenError<std::runtime_error>([] (auto const& e) { LOG(INFO) << "std::runtime_error: " << e.what(); return -1; // or makeFuture<int>(-1) or makeSemiFuture<int>(-1) });

Preconditions:

Postconditions:

  • valid() == false
  • RESULT.valid() == true

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

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

1092  {
1093  // Forward to onError but ensure that returned future carries the executor
1094  // Allow for applying to future with null executor while this is still
1095  // possible.
1096  auto* e = this->getExecutor();
1097  return std::move(*this)
1098  .onError([func = std::forward<F>(func)](ExceptionType& ex) mutable {
1099  return std::forward<F>(func)(ex);
1100  })
1101  .via(e ? e : &InlineExecutor::instance());
1102 }
Future< T > via(Executor *executor, int8_t priority=Executor::MID_PRI)&&
Definition: Future-inl.h:1024
Executor * getExecutor() const
Definition: Future.h:412
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
FOLLY_ATTR_VISIBILITY_HIDDEN static FOLLY_ALWAYS_INLINE InlineExecutor & instance() noexcept
template<class T>
template<class ExceptionType , class R , class... Args>
Future<T> folly::Future< T >::thenError ( R(&)(Args...)  func)
inline

Definition at line 1361 of file Future.h.

1361  {
1362  return std::move(*this).template thenError<ExceptionType>(&func);
1363  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T >
template<class F >
Future< T > folly::Future< T >::thenError ( F &&  func)

Set an error continuation for this Future where the continuation can be called with exception_wrapper&& and returns a T, Future<T>, or SemiFuture<T>.

Example:

makeFuture() .thenTry([] { throw std::runtime_error("oh no!"); return 42; }) .thenError([] (exception_wrapper&& e) { LOG(INFO) << e.what(); return -1; // or makeFuture<int>(-1) or makeSemiFuture<int>(-1) });

Preconditions:

Postconditions:

  • valid() == false
  • RESULT.valid() == true

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

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

1106  {
1107  // Forward to onError but ensure that returned future carries the executor
1108  // Allow for applying to future with null executor while this is still
1109  // possible.
1110  auto* e = this->getExecutor();
1111  return std::move(*this)
1112  .onError([func = std::forward<F>(func)](
1113  folly::exception_wrapper&& ex) mutable {
1114  return std::forward<F>(func)(std::move(ex));
1115  })
1116  .via(e ? e : &InlineExecutor::instance());
1117 }
Future< T > via(Executor *executor, int8_t priority=Executor::MID_PRI)&&
Definition: Future-inl.h:1024
Executor * getExecutor() const
Definition: Future.h:412
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
FOLLY_ATTR_VISIBILITY_HIDDEN static FOLLY_ALWAYS_INLINE InlineExecutor & instance() noexcept
template<class T>
template<class R , class... Args>
Future<T> folly::Future< T >::thenError ( R(&)(Args...)  func)
inline

Definition at line 1393 of file Future.h.

1393  {
1394  return std::move(*this).thenError(&func);
1395  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T>
template<class Callback , class... Callbacks>
auto folly::Future< T >::thenMulti ( Callback &&  fn,
Callbacks &&...  fns 
)
inline

Create a Future chain from a sequence of continuations. i.e.

f.then(a).then(b).then(c)

where f is a Future and the result of the chain is a Future<D> becomes

std::move(f).thenMulti(a, b, c);

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true

Definition at line 1825 of file Future.h.

1825  {
1826  // thenMulti with two callbacks is just then(a).thenMulti(b, ...)
1827 
1828  // TODO(T29171940): Switch to thenImplementation here. It is ambiguous
1829  // as then used to be but that is better than keeping then in the public
1830  // API.
1831  using R = futures::detail::callableResult<T, decltype(fn)>;
1832  return std::move(*this)
1833  .thenImplementation(std::forward<Callback>(fn), R{})
1834  .thenMulti(std::forward<Callbacks>(fns)...);
1835  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
auto thenMulti(Callback &&fn, Callbacks &&...fns)&&
Definition: Future.h:1825
template<class T>
template<class Callback >
auto folly::Future< T >::thenMulti ( Callback &&  fn)
inline

Create a Future chain from a sequence of callbacks.

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true

Definition at line 1849 of file Future.h.

1849  {
1850  // thenMulti with one callback is just a then
1851 
1852  // TODO(T29171940): Switch to thenImplementation here. It is ambiguous
1853  // as then used to be but that is better than keeping then in the public
1854  // API.
1855  using R = futures::detail::callableResult<T, decltype(fn)>;
1856  return std::move(*this).thenImplementation(std::forward<Callback>(fn), R{});
1857  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T>
template<class Callback >
auto folly::Future< T >::thenMulti ( Callback &&  fn)
inline

Definition at line 1860 of file Future.h.

1860  {
1861  return std::move(*this).thenMulti(std::forward<Callback>(fn));
1862  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T>
template<class Callback , class... Callbacks>
auto folly::Future< T >::thenMultiWithExecutor ( Executor x,
Callback &&  fn,
Callbacks &&...  fns 
)
inline

Create a Future chain from a sequence of callbacks. i.e.

f.via(executor).then(a).then(b).then(c).via(oldExecutor)

where f is a Future and the result of the chain is a Future<D> becomes

std::move(f).thenMultiWithExecutor(executor, a, b, c);

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true

Definition at line 1884 of file Future.h.

1884  {
1885  // thenMultiExecutor with two callbacks is
1886  // via(x).then(a).thenMulti(b, ...).via(oldX)
1887  auto oldX = this->getExecutor();
1888  this->setExecutor(x);
1889  // TODO(T29171940): Switch to thenImplementation here. It is ambiguous
1890  // as then used to be but that is better than keeping then in the public
1891  // API.
1892  using R = futures::detail::callableResult<T, decltype(fn)>;
1893  return std::move(*this)
1894  .thenImplementation(std::forward<Callback>(fn), R{})
1895  .thenMulti(std::forward<Callbacks>(fns)...)
1896  .via(oldX);
1897  }
Definition: InvokeTest.cpp:58
Executor * getExecutor() const
Definition: Future.h:412
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
auto thenMulti(Callback &&fn, Callbacks &&...fns)&&
Definition: Future.h:1825
void setExecutor(Executor *x, int8_t priority=Executor::MID_PRI)
Definition: Future.h:420
template<class T>
template<class Callback >
auto folly::Future< T >::thenMultiWithExecutor ( Executor x,
Callback &&  fn 
)
inline

Definition at line 1900 of file Future.h.

1900  {
1901  // thenMulti with one callback is just a then with an executor
1902  return std::move(*this).then(x, std::forward<Callback>(fn));
1903  }
Definition: InvokeTest.cpp:58
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T >
template<typename F >
Future< typename futures::detail::tryCallableResult< T, F >::value_type > folly::Future< T >::thenTry ( F &&  func)

When this Future has completed, execute func which is a function that can be called with Try<T>&& (often a lambda with parameter type auto&& or auto).

Func shall return either another Future or a value.

A Future for the return type of func is returned.

Future<string> f2 = std::move(f1).thenTry([](auto&& t) { ... return string("foo"); });

Preconditions:

Postconditions:

  • valid() == false
  • RESULT.valid() == true

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

References f, folly::gen::move, folly::pushmi::detail::t, and folly::futures::detail::FutureBase< T >::thenImplementation().

1068  {
1069  auto lambdaFunc = [f = std::forward<F>(func)](folly::Try<T>&& t) mutable {
1070  return std::forward<F>(f)(std::move(t));
1071  };
1072  using R = futures::detail::tryCallableResult<T, decltype(lambdaFunc)>;
1073  return this->thenImplementation(std::move(lambdaFunc), R{});
1074 }
auto f
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::enable_if<!R::ReturnsFuture::value, typename R::Return >::type thenImplementation(F &&func, R)
Definition: Future-inl.h:311
Definition: Try.h:51
template<class T>
template<typename R , typename... Args>
auto folly::Future< T >::thenTry ( R(&)(Args...)  func)
inline

Definition at line 1299 of file Future.h.

1299  {
1300  return std::move(*this).thenTry(&func);
1301  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T >
template<typename F >
Future< typename futures::detail::valueCallableResult< T, F >::value_type > folly::Future< T >::thenValue ( F &&  func)

When this Future has completed, execute func which is a function that can be called with T&& (often a lambda with parameter type auto&& or auto).

Func shall return either another Future or a value.

A Future for the return type of func is returned.

Future<string> f2 = f1.thenValue([](auto&& v) { ... return string("foo"); });

Preconditions:

Postconditions:

  • valid() == false
  • RESULT.valid() == true

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

References f, folly::gen::move, folly::pushmi::detail::t, and folly::futures::detail::FutureBase< T >::thenImplementation().

Referenced by folly::Future< T >::Future(), and folly::Future< T >::operator=().

1079  {
1080  auto lambdaFunc = [f = std::forward<F>(func)](folly::Try<T>&& t) mutable {
1081  return std::forward<F>(f)(
1082  t.template get<
1083  false,
1085  };
1086  using R = futures::detail::tryCallableResult<T, decltype(lambdaFunc)>;
1087  return this->thenImplementation(std::move(lambdaFunc), R{});
1088 }
auto f
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::enable_if<!R::ReturnsFuture::value, typename R::Return >::type thenImplementation(F &&func, R)
Definition: Future-inl.h:311
Definition: Try.h:51
template<class T>
template<typename R , typename... Args>
auto folly::Future< T >::thenValue ( R(&)(Args...)  func)
inline

Definition at line 1329 of file Future.h.

1329  {
1330  return std::move(*this).thenValue(&func);
1331  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T>
Future<Unit> folly::Future< T >::unit ( )
inline

Convenience method for ignoring the value and creating a Future<Unit>. Exceptions still propagate. This function is identical to parameterless .then().

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true

Definition at line 1431 of file Future.h.

1431  {
1432  return std::move(*this).then();
1433  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T >
template<class F >
std::enable_if< isFuture< F >::value, Future< typename isFuture< T >::Inner > >::type folly::Future< T >::unwrap ( )

Unwraps the case of a Future<Future<T>> instance, and returns a simple Future<T> instance.

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true

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

References folly::gen::move.

1007  {
1008  return std::move(*this).thenValue(
1009  [](Future<typename isFuture<T>::Inner> internal_future) {
1010  return internal_future;
1011  });
1012 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
typename lift_unit< T >::type Inner
Definition: Future-pre.h:40
friend class Future
Definition: Future.h:1933
template<class T >
Future< T > folly::Future< T >::via ( Executor executor,
int8_t  priority = Executor::MID_PRI 
)

Returns a Future which will call back on the other side of executor.

Preconditions:

Postconditions:

  • valid() == false
  • RESULT.valid() == true

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

References testing::Args(), folly::futures::detail::FutureBase< T >::core_, folly::pushmi::executor, f, folly::getKeepAliveToken(), folly::Promise< T >::getSemiFuture(), int8_t, folly::gen::move, folly::Promise< T >::setTry(), folly::pushmi::detail::t, folly::futures::detail::FutureBase< T >::thenImplementation(), and folly::futures::detail::FutureBase< T >::throwIfInvalid().

Referenced by fizz::sm::getCertificateRequest(), folly::Future< T >::thenError(), folly::via(), and folly::window().

1024  {
1025  return std::move(*this).via(getKeepAliveToken(executor), priority);
1026 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
Executor::KeepAlive< ExecutorT > getKeepAliveToken(ExecutorT *executor)
Definition: Executor.h:200
template<class T >
Future< T > folly::Future< T >::via ( Executor::KeepAlive<>  executor,
int8_t  priority = Executor::MID_PRI 
)

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

References folly::futures::detail::FutureBase< T >::core_, folly::pushmi::executor, folly::gen::move, and folly::futures::detail::FutureBase< T >::setExecutor().

1015  {
1016  this->setExecutor(std::move(executor), priority);
1017 
1018  auto newFuture = Future<T>(this->core_);
1019  this->core_ = nullptr;
1020  return newFuture;
1021 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
PUSHMI_INLINE_VAR constexpr __adl::get_executor_fn executor
void setExecutor(Executor *x, int8_t priority=Executor::MID_PRI)
Definition: Future.h:420
template<class T>
Future<T> folly::Future< T >::via ( Executor executor,
int8_t  priority = Executor::MID_PRI 
)

Returns a Future which will call back on the other side of executor.

When practical, use the rvalue-qualified overload instead - it's faster.

Preconditions:

Postconditions:

  • valid() == true
  • RESULT.valid() == true
  • when this gets fulfilled, it automatically fulfills RESULT
template<class T>
Future<T> folly::Future< T >::via ( Executor::KeepAlive<>  executor,
int8_t  priority = Executor::MID_PRI 
)
template<class T >
Future< T > && folly::Future< T >::wait ( )

Blocks until this Future is complete.

Preconditions:

Postconditions:

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

References folly::gen::move, and folly::futures::detail::waitImpl().

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

2197  {
2199  return *this;
2200 }
void waitImpl(FutureType &f)
Definition: Future-inl.h:2004
template<class T>
Future<T>&& folly::Future< T >::wait ( )

Blocks until this Future is complete.

Preconditions:

Postconditions:

  • valid() == true (but the calling code can trivially move-out *this by assigning or constructing the result into a distinct object).
  • &RESULT == this
  • isReady() == true
template<class T >
Future< T > && folly::Future< T >::wait ( Duration  dur)

Blocks until this Future is complete, or dur elapses.

Preconditions:

Postconditions:

  • valid() == true (so you may call wait(...) repeatedly)
  • &RESULT == this
  • isReady() will be indeterminate - may or may not be true

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

References folly::gen::move, folly::Future< T >::wait(), and folly::futures::detail::waitImpl().

2209  {
2210  futures::detail::waitImpl(*this, dur);
2211  return *this;
2212 }
void waitImpl(FutureType &f)
Definition: Future-inl.h:2004
template<class T>
Future<T>&& folly::Future< T >::wait ( Duration  dur)

Blocks until this Future is complete or until dur passes.

Preconditions:

Postconditions:

  • valid() == true (but the calling code can trivially move-out *this by assigning or constructing the result into a distinct object).
  • &RESULT == this
  • isReady() will be indeterminate - may or may not be true
template<class T >
Future< T > && folly::Future< T >::waitVia ( DrivableExecutor e)

Call e->drive() repeatedly until the future is fulfilled. Examples of DrivableExecutor include EventBase and ManualExecutor. Returns a reference to this Future so that you can chain calls if desired. value (moved-out), or throws the exception.

Preconditions:

Postconditions:

  • valid() == true (does not move-out *this)
  • &RESULT == this

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

References folly::gen::move, and folly::futures::detail::waitViaImpl().

Referenced by folly::Future< T >::getTryVia(), folly::Future< T >::getVia(), and folly::Future< T >::waitVia().

2221  {
2222  futures::detail::waitViaImpl(*this, e);
2223  return *this;
2224 }
void waitViaImpl(Future< T > &f, DrivableExecutor *e)
Definition: Future-inl.h:2061
template<class T>
Future<T>&& folly::Future< T >::waitVia ( DrivableExecutor e)

Overload of waitVia() for rvalue Futures

Preconditions:

Postconditions:

  • valid() == true (but the calling code can trivially move-out *this by assigning or constructing the result into a distinct object).
  • &RESULT == this
template<class T >
Future< T > && folly::Future< T >::waitVia ( TimedDrivableExecutor e,
Duration  dur 
)

As waitVia but may return early after dur passes.

Preconditions:

Postconditions:

  • valid() == true (does not move-out *this)
  • &RESULT == this

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

References folly::gen::move, folly::Future< T >::waitVia(), and folly::futures::detail::waitViaImpl().

2233  {
2234  futures::detail::waitViaImpl(*this, e, dur);
2235  return *this;
2236 }
void waitViaImpl(Future< T > &f, DrivableExecutor *e)
Definition: Future-inl.h:2061
template<class T>
Future<T>&& folly::Future< T >::waitVia ( TimedDrivableExecutor e,
Duration  dur 
)

Overload of waitVia() for rvalue Futures As waitVia but may return early after dur passes.

Preconditions:

Postconditions:

  • valid() == true (but the calling code can trivially move-out *this by assigning or constructing the result into a distinct object).
  • &RESULT == this
template<class T>
Future< bool > folly::Future< T >::willEqual ( Future< T > &  f)

If the value in this Future is equal to the given Future, when they have both completed, the value of the resulting Future<bool> will be true. It will be false otherwise (including when one or both Futures have an exception)

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

References folly::collectAllSemiFuture(), folly::futures::detail::TryEquals< T >::equals(), folly::futures::detail::FutureBase< T >::hasValue(), and folly::pushmi::detail::t.

2305  {
2306  return collectAllSemiFuture(*this, f).toUnsafeFuture().thenValue(
2307  [](const std::tuple<Try<T>, Try<T>>& t) {
2308  if (std::get<0>(t).hasValue() && std::get<1>(t).hasValue()) {
2310  std::get<0>(t), std::get<1>(t));
2311  } else {
2312  return false;
2313  }
2314  });
2315 }
auto f
SemiFuture< std::tuple< Try< typename remove_cvref_t< Fs >::value_type >... > > collectAllSemiFuture(Fs &&...fs)
Definition: Future-inl.h:1441
static bool equals(const Try< T > &t1, const Try< T > &t2)
Definition: Future-inl.h:2297
template<class T >
Future< T > folly::Future< T >::within ( Duration  dur,
Timekeeper tk = nullptr 
)

Throw FutureTimeout if this Future does not complete within the given duration from now. The optional Timekeeper is as with futures::sleep().

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true

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

References folly::gen::move.

1966  {
1967  return std::move(*this).within(dur, FutureTimeout(), tk);
1968 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class T >
template<class E >
Future< T > folly::Future< T >::within ( Duration  dur,
E  exception,
Timekeeper tk = nullptr 
)

Throw the given exception if this Future does not complete within the given duration from now. The optional Timekeeper is as with futures::sleep().

Preconditions:

Postconditions:

  • Calling code should act as if valid() == false, i.e., as if *this was moved into RESULT.
  • RESULT.valid() == true

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

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

1972  {
1973  if (this->isReady()) {
1974  return std::move(*this);
1975  }
1976 
1977  auto* exe = this->getExecutor();
1978  return std::move(*this)
1979  .withinImplementation(dur, e, tk)
1980  .via(exe ? exe : &InlineExecutor::instance());
1981 }
Executor * getExecutor() const
Definition: Future.h:412
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
FOLLY_ATTR_VISIBILITY_HIDDEN static FOLLY_ALWAYS_INLINE InlineExecutor & instance() noexcept
InlineExecutor exe
Definition: Benchmark.cpp:337

Friends And Related Function Documentation

template<class T>
template<class >
friend class Future
friend

Definition at line 1933 of file Future.h.

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

template<class T>
template<class FT >
void futures::detail::convertFuture ( SemiFuture< FT > &&  sf,
Future< FT > &  f 
)
friend
template<class T>
template<class >
friend class futures::detail::FutureBase
friend

Definition at line 1931 of file Future.h.

template<class T>
template<class >
friend class FutureSplitter
friend

Definition at line 1937 of file Future.h.

template<class T>
template<class T2 >
Future<T2> makeFuture ( Try< T2 )
friend
template<class T>
friend class Promise< T >
friend

Definition at line 1929 of file Future.h.

template<class T>
template<class >
friend class SemiFuture
friend

Definition at line 1935 of file Future.h.

template<class T>
template<class F >
Future<Unit> times ( int  n,
F &&  thunk 
)
friend

Repeat the given future (i.e., the computation it contains) n times.

thunk behaves like std::function<Future<T2>(void)>

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

Referenced by folly::window().

2348  {
2349  return folly::whileDo(
2350  [n, count = std::make_unique<std::atomic<int>>(0)]() mutable {
2351  return count->fetch_add(1, std::memory_order_relaxed) < n;
2352  },
2353  std::forward<F>(thunk));
2354 }
Future< Unit > whileDo(P &&predicate, F &&thunk)
Definition: Future-inl.h:2335
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&...args)
Definition: Memory.h:259
int * count
template<class T>
template<class F >
Future<Unit> when ( bool  p,
F &&  thunk 
)
friend

Carry out the computation contained in the given future if the predicate holds.

thunk behaves like std::function<Future<T2>(void)>

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

2330  {
2331  return p ? std::forward<F>(thunk)().unit() : makeFuture();
2332 }
friend Future< T2 > makeFuture(Try< T2 >)
template<class T>
template<class P , class F >
Future<Unit> whileDo ( P &&  predicate,
F &&  thunk 
)
friend

Carry out the computation contained in the given future if while the predicate continues to hold.

thunk behaves like std::function<Future<T2>(void)>

predicate behaves like std::function<bool(void)>

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

Referenced by folly::whileDo().

2335  {
2336  if (predicate()) {
2337  auto future = thunk();
2338  return std::move(future).thenValue(
2339  [predicate = std::forward<P>(predicate),
2340  thunk = std::forward<F>(thunk)](auto&&) mutable {
2341  return whileDo(std::forward<P>(predicate), std::forward<F>(thunk));
2342  });
2343  }
2344  return makeFuture();
2345 }
friend Future< T2 > makeFuture(Try< T2 >)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
friend Future< Unit > whileDo(P &&predicate, F &&thunk)
Definition: Future-inl.h:2335

The documentation for this class was generated from the following files: