proxygen
|
#include <FiberManagerInternal.h>
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> | |
Future & | operator= (Future< T2 > &&) |
Future & | operator= (Future const &)=delete |
Future & | operator= (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< T > | via (Executor *executor, int8_t priority=Executor::MID_PRI)&& |
Future< T > | via (Executor::KeepAlive<> executor, int8_t priority=Executor::MID_PRI)&& |
Future< T > | via (Executor *executor, int8_t priority=Executor::MID_PRI)& |
Future< T > | via (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_type > | thenTry (F &&func)&& |
template<typename R , typename... Args> | |
auto | thenTry (R(&func)(Args...))&& |
template<typename F > | |
Future< typename futures::detail::valueCallableResult< T, F >::value_type > | thenValue (F &&func)&& |
template<typename R , typename... Args> | |
auto | thenValue (R(&func)(Args...))&& |
template<class ExceptionType , class F > | |
Future< T > | thenError (F &&func)&& |
template<class ExceptionType , class R , class... Args> | |
Future< T > | thenError (R(&func)(Args...))&& |
template<class F > | |
Future< T > | thenError (F &&func)&& |
template<class R , class... Args> | |
Future< T > | thenError (R(&func)(Args...))&& |
Future< Unit > | then ()&& |
Future< Unit > | then ()&=delete |
Future< Unit > | unit ()&& |
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< T > | onError (F &&func)& |
template<class F > | |
Future< T > | ensure (F &&func)&& |
template<class F > | |
Future< T > | onTimeout (Duration, F &&func, Timekeeper *=nullptr)&& |
Future< T > | within (Duration dur, Timekeeper *tk=nullptr)&& |
template<class E > | |
Future< T > | within (Duration dur, E exception, Timekeeper *tk=nullptr)&& |
Future< T > | delayed (Duration, Timekeeper *=nullptr)&& |
Future< T > | delayedUnsafe (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< T > | filter (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< T > | semi ()&& |
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< T > | makeEmpty () |
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 > |
![]() | |
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< T2 > | makeFuture (Try< T2 >) |
template<class F > | |
Future< Unit > | times (int n, F &&thunk) |
template<class F > | |
Future< Unit > | when (bool p, F &&thunk) |
template<class P , class F > | |
Future< Unit > | whileDo (P &&predicate, F &&thunk) |
template<class FT > | |
void | futures::detail::convertFuture (SemiFuture< FT > &&sf, Future< FT > &f) |
Additional Inherited Members | |
![]() | |
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 |
T & | value ()& |
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 |
Core & | getCore () |
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 |
Executor * | getExecutor () 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< T > | withinImplementation (Duration dur, E e, Timekeeper *tk)&& |
![]() | |
template<typename Self > | |
static decltype(auto) | getCoreImpl (Self &self) |
template<typename Self > | |
static decltype(auto) | getCoreTryChecked (Self &self) |
![]() | |
Core * | core_ |
The interface (along with SemiFuture) for the consumer-side of a producer/consumer pair.
Future vs. SemiFuture:
SemiFuture
, not a Future..thenValue
, etc.) can be specified by the library's caller (using .via()
)..via()
.makePromiseContract()
when creating both a Promise and an associated SemiFuture/Future.When practical, prefer SemiFuture/Future's nonblocking style/pattern:
.thenValue
, etc.; the continuations are deferred until the result is available..wait()
, .get()
, etc.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.
|
private |
|
protected |
typedef T folly::futures::detail::FutureBase< T >::value_type |
|
inline |
|
inline |
Construct a (logical) Future-of-void.
Postconditions:
valid() == true
isReady() == true
hasValue() == true
Definition at line 991 of file Future.h.
|
inlineexplicit |
Construct a Future from a T
constructed from args
Postconditions:
valid() == true
isReady() == true
hasValue() == true
hasException() == false
value()
, get()
, result()
will return the newly constructed T
Definition at line 1008 of file Future.h.
|
delete |
|
noexcept |
Definition at line 956 of file Future-inl.h.
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().
|
explicit |
|
inlineexplicitprotected |
|
inlineexplicitprotectednoexcept |
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:
valid() == true
(else throws FutureInvalid)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().
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.
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:
valid() == true
(else throws FutureInvalid)Postconditions:
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.
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:
valid() == true
(else throws FutureInvalid)Postconditions:
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.
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:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == false
Definition at line 2245 of file Future-inl.h.
References folly::copy(), folly::gen::move, and folly::Future< T >::wait().
|
delete |
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:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == false
Definition at line 2251 of file Future-inl.h.
References folly::copy(), folly::gen::move, and folly::Future< T >::wait().
|
delete |
Try< T > & folly::Future< T >::getTry | ( | ) |
A reference to the Try of the value
Preconditions:
valid() == true
(else throws FutureInvalid)isReady() == true
(else throws FutureNotReady) Definition at line 2261 of file Future-inl.h.
References folly::futures::detail::FutureBase< T >::result().
Referenced by folly::SemiFuture< T >::getTry().
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().
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().
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().
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().
|
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().
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:
valid() == true
(else throws FutureInvalid)Postconditions:
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().
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:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == false
, i.e., as if *this
was moved into RESULT.RESULT.valid() == true
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:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == false
, i.e., as if *this
was moved into RESULT.RESULT.valid() == true
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:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == false
, i.e., as if *this
was moved into RESULT.RESULT.valid() == true
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:
valid() == true
(else throws FutureInvalid)Postconditions:
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().
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.
Future& folly::Future< T >::operator= | ( | Future< T2 > && | ) |
Referenced by folly::Future< T >::operator=().
|
delete |
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().
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:
valid() == true
(else throws FutureInvalid)Postconditions:
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.
|
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()
*this
had one Definition at line 1912 of file Future.h.
|
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:
valid() == true
(else throws FutureInvalid)Postconditions:
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.
|
inline |
|
delete |
|
delete |
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:
valid() == true
(else throws FutureInvalid)Postconditions:
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.
|
delete |
|
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:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == false
, i.e., as if *this
was moved into RESULT.RESULT.valid() == true
Definition at line 1247 of file Future.h.
|
inline |
Definition at line 1261 of file Future.h.
|
delete |
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:
valid() == true
(else throws FutureInvalid)Postconditions:
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.
|
delete |
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:
valid() == true
(else throws FutureInvalid)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().
|
inline |
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:
valid() == true
(else throws FutureInvalid)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().
|
inline |
|
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:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == false
, i.e., as if *this
was moved into RESULT.RESULT.valid() == true
Definition at line 1825 of file Future.h.
|
inline |
|
inline |
|
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:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == false
, i.e., as if *this
was moved into RESULT.RESULT.valid() == true
Definition at line 1884 of file Future.h.
|
inline |
Definition at line 1900 of file Future.h.
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:
valid() == true
(else throws FutureInvalid)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().
|
inline |
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:
valid() == true
(else throws FutureInvalid)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=().
|
inline |
|
inline |
Convenience method for ignoring the value and creating a Future<Unit>. Exceptions still propagate. This function is identical to parameterless .then().
Preconditions:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == false
, i.e., as if *this
was moved into RESULT.RESULT.valid() == true
Definition at line 1431 of file Future.h.
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:
valid() == true
(else throws FutureInvalid)Postconditions:
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.
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:
valid() == true
(else throws FutureInvalid)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().
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().
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:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == true
RESULT.valid() == true
this
gets fulfilled, it automatically fulfills RESULT Future<T> folly::Future< T >::via | ( | Executor::KeepAlive<> | executor, |
int8_t | priority = Executor::MID_PRI |
||
) |
Future< T > && folly::Future< T >::wait | ( | ) |
Blocks until this Future is complete.
Preconditions:
valid() == true
(else throws FutureInvalid)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().
Future<T>&& folly::Future< T >::wait | ( | ) |
Blocks until this Future is complete.
Preconditions:
valid() == true
(else throws FutureInvalid)Postconditions:
Future< T > && folly::Future< T >::wait | ( | Duration | dur | ) |
Blocks until this Future is complete, or dur
elapses.
Preconditions:
valid() == true
(else throws FutureInvalid)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().
Future<T>&& folly::Future< T >::wait | ( | Duration | dur | ) |
Blocks until this Future is complete or until dur
passes.
Preconditions:
valid() == true
(else throws FutureInvalid)Postconditions:
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:
valid() == true
(else throws FutureInvalid)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().
Future<T>&& folly::Future< T >::waitVia | ( | DrivableExecutor * | e | ) |
Overload of waitVia() for rvalue Futures
Preconditions:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == true
(but the calling code can trivially move-out *this
by assigning or constructing the result into a distinct object).&RESULT == this
Future< T > && folly::Future< T >::waitVia | ( | TimedDrivableExecutor * | e, |
Duration | dur | ||
) |
As waitVia but may return early after dur passes.
Preconditions:
valid() == true
(else throws FutureInvalid)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().
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:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == true
(but the calling code can trivially move-out *this
by assigning or constructing the result into a distinct object).&RESULT == this
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.
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:
valid() == true
(else throws FutureInvalid)Postconditions:
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.
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:
valid() == true
(else throws FutureInvalid)Postconditions:
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.
Definition at line 1933 of file Future.h.
Referenced by folly::Future< T >::Future().
|
friend |
Referenced by folly::Timekeeper::at(), folly::makeFuture(), folly::reduce(), folly::unorderedReduce(), folly::via(), folly::when(), and folly::whileDo().
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().
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.
|
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().