proxygen
|
#include <Future-pre.h>
Public Types | |
typedef T | value_type |
Public Member Functions | |
~SemiFuture () | |
template<class T2 = T, typename = typename std::enable_if< !isFuture<typename std::decay<T2>::type>::value && !isSemiFuture<typename std::decay<T2>::type>::value>::type> | |
SemiFuture (T2 &&val) | |
template<class T2 = T> | |
SemiFuture (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> | |
SemiFuture (in_place_t, Args &&...args) | |
SemiFuture (SemiFuture< T > const &)=delete | |
SemiFuture (SemiFuture< T > &&) noexcept | |
SemiFuture (Future< T > &&) noexcept | |
SemiFuture & | operator= (SemiFuture const &)=delete |
SemiFuture & | operator= (SemiFuture &&) noexcept |
SemiFuture & | operator= (Future< T > &&) noexcept |
T | get ()&& |
T | get ()&=delete |
T | get (Duration dur)&& |
T | get (Duration dur)&=delete |
Try< T > | getTry ()&& |
Try< T > | getTry (Duration dur)&& |
SemiFuture< T > & | wait ()& |
SemiFuture< T > && | wait ()&& |
bool | wait (Duration dur)&& |
Future< T > | via (Executor *executor, int8_t priority=Executor::MID_PRI)&& |
Returns a Future which will call back on the other side of executor. More... | |
Future< T > | via (Executor::KeepAlive<> executor, int8_t priority=Executor::MID_PRI)&& |
template<typename F > | |
SemiFuture< typename futures::detail::tryCallableResult< T, F >::value_type > | defer (F &&func)&& |
template<typename R , typename... Args> | |
auto | defer (R(&func)(Args...))&& |
template<typename F > | |
SemiFuture< typename futures::detail::valueCallableResult< T, F >::value_type > | deferValue (F &&func)&& |
template<typename R , typename... Args> | |
auto | deferValue (R(&func)(Args...))&& |
template<class ExceptionType , class F > | |
SemiFuture< T > | deferError (F &&func)&& |
template<class ExceptionType , class R , class... Args> | |
SemiFuture< T > | deferError (R(&func)(Args...))&& |
template<class F > | |
SemiFuture< T > | deferError (F &&func)&& |
template<class R , class... Args> | |
SemiFuture< T > | deferError (R(&func)(Args...))&& |
SemiFuture< T > | within (Duration dur, Timekeeper *tk=nullptr)&& |
template<class E > | |
SemiFuture< T > | within (Duration dur, E e, Timekeeper *tk=nullptr)&& |
SemiFuture< T > | delayed (Duration dur, Timekeeper *tk=nullptr)&& |
Future< T > | toUnsafeFuture ()&& |
Static Public Member Functions | |
static SemiFuture< T > | makeEmpty () |
Private Types | |
using | Base = futures::detail::FutureBase< T > |
using | DeferredExecutor = futures::detail::DeferredExecutor |
using | TimePoint = std::chrono::system_clock::time_point |
using | Core = futures::detail::Core< T > |
Private Types inherited from folly::futures::detail::FutureBase< T > | |
typedef T | value_type |
using | Core = futures::detail::Core< T > |
Private Member Functions | |
SemiFuture (Core *obj) | |
SemiFuture (futures::detail::EmptyConstruct) noexcept | |
DeferredExecutor * | getDeferredExecutor () const |
folly::Executor::KeepAlive< DeferredExecutor > | stealDeferredExecutor () const |
SemiFuture< T > & | wait (Duration dur)& |
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 |
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)&& |
Static Private Member Functions | |
static void | releaseDeferredExecutor (Core *core) |
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) |
Friends | |
class | Promise< T > |
template<class > | |
class | futures::detail::FutureBase |
template<class > | |
class | SemiFuture |
template<class > | |
class | Future |
folly::Executor::KeepAlive< DeferredExecutor > | futures::detail::stealDeferredExecutor (SemiFuture &) |
DeferredExecutor * | futures::detail::getDeferredExecutor (SemiFuture &) |
template<class T2 > | |
SemiFuture< T2 > | makeSemiFuture (Try< T2 >) |
Additional Inherited Members | |
Private Attributes inherited from folly::futures::detail::FutureBase< T > | |
Core * | core_ |
The interface (along with Future) 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 26 of file Future-pre.h.
|
private |
|
private |
|
private |
|
private |
typedef T folly::futures::detail::FutureBase< T >::value_type |
folly::SemiFuture< T >::~SemiFuture | ( | ) |
Definition at line 815 of file Future-inl.h.
References folly::futures::detail::FutureBase< T >::core_.
|
inline |
Construct a SemiFuture from a value (perfect forwarding)
Postconditions:
valid() == true
isReady() == true
hasValue() == true
hasException() == false
value()
, get()
, result()
will return the forwarded T
Definition at line 521 of file Future.h.
|
inline |
Construct a (logical) SemiFuture-of-void.
Postconditions:
valid() == true
isReady() == true
hasValue() == true
Definition at line 531 of file Future.h.
References testing::Args(), folly::T, type, and folly::value().
|
inlineexplicit |
Construct a SemiFuture 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 548 of file Future.h.
References testing::Args(), folly::pushmi::operators::defer, folly::pushmi::executor, int8_t, folly::Executor::MID_PRI, folly::pushmi::__adl::noexcept(), folly::netops::poll(), value, folly::via(), and folly::detail::distributed_mutex::wait().
|
delete |
|
noexcept |
Definition at line 820 of file Future-inl.h.
|
noexcept |
Definition at line 824 of file Future-inl.h.
References folly::futures::detail::FutureBase< T >::core_, and folly::futures::detail::FutureBase< T >::setExecutor().
|
inlineexplicitprivate |
|
inlineexplicitprivatenoexcept |
Definition at line 899 of file Future.h.
References folly::futures::detail::getDeferredExecutor(), folly::futures::detail::stealDeferredExecutor(), and folly::detail::distributed_mutex::wait().
SemiFuture< typename futures::detail::tryCallableResult< T, F >::value_type > folly::SemiFuture< T >::defer | ( | F && | func | ) |
Defer work to run on the consumer of the future. Function must take a Try as a parameter. This work will be run either on an executor that the caller sets on the SemiFuture, or inline with the call to .get().
NB: This is a custom method because boost-blocking executors is a special-case for work deferral in folly. With more general boost-blocking support all executors would boost block and we would simply use some form of driveable executor here.
Preconditions:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == false
RESULT.valid() == true
Definition at line 882 of file Future-inl.h.
References folly::futures::detail::FutureBase< T >::core_, folly::futures::detail::DeferredExecutor::create(), folly::futures::detail::getDeferredExecutor(), folly::gen::move, folly::futures::detail::FutureBase< T >::setExecutor(), and folly::futures::detail::Core< T >::setExecutor().
|
inline |
SemiFuture< T > folly::SemiFuture< T >::deferError | ( | F && | func | ) |
Set an error continuation for this SemiFuture where the continuation can be called with a known exception type and returns a T
, Future<T>
, or SemiFuture<T>
.
Example:
Preconditions:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == false
RESULT.valid() == true
Definition at line 913 of file Future-inl.h.
References folly::gen::move, and folly::pushmi::detail::t.
|
inline |
SemiFuture< T > folly::SemiFuture< T >::deferError | ( | F && | func | ) |
Set an error continuation for this SemiFuture where the continuation can be called with exception_wrapper&&
and returns a T
, Future<T>
, or SemiFuture<T>
.
Example:
makeSemiFuture() .defer([] { throw std::runtime_error("oh no!"); return 42; }) .deferError([] (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 927 of file Future-inl.h.
References folly::gen::move, and folly::pushmi::detail::t.
|
inline |
SemiFuture< typename futures::detail::valueCallableResult< T, F >::value_type > folly::SemiFuture< T >::deferValue | ( | F && | func | ) |
Defer for functions taking a T rather than a Try<T>.
Preconditions:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == false
RESULT.valid() == true
Definition at line 901 of file Future-inl.h.
References f, folly::gen::move, and folly::pushmi::detail::t.
|
inline |
SemiFuture< T > folly::SemiFuture< T >::delayed | ( | Duration | dur, |
Timekeeper * | tk = nullptr |
||
) |
Delay the completion of this SemiFuture 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 941 of file Future-inl.h.
References folly::collectAllSemiFuture(), folly::gen::move, folly::futures::sleep(), and folly::pushmi::detail::t.
T folly::SemiFuture< T >::get | ( | ) |
Blocks until the promise is fulfilled, either by value (which is returned) or exception (which is thrown).
Preconditions:
valid() == true
(else throws FutureInvalid).thenValue()
or similarPostconditions:
valid() == false
Definition at line 2167 of file Future-inl.h.
References folly::gen::move.
|
delete |
T folly::SemiFuture< T >::get | ( | Duration | dur | ) |
Blocks until the semifuture 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 2172 of file Future-inl.h.
References folly::gen::move.
|
delete |
|
private |
Definition at line 780 of file Future-inl.h.
References folly::pushmi::executor, and folly::futures::detail::FutureBase< T >::getExecutor().
Referenced by folly::futures::detail::getDeferredExecutor().
Try< T > folly::SemiFuture< T >::getTry | ( | ) |
Blocks until the future is fulfilled. Returns the Try of the result (moved-out).
Preconditions:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == false
Definition at line 2177 of file Future-inl.h.
References folly::futures::detail::FutureBase< T >::core_, folly::Future< T >::getTry(), folly::gen::move, and folly::Future< T >::wait().
Try< T > folly::SemiFuture< T >::getTry | ( | Duration | dur | ) |
Blocks until the future is fulfilled, or until dur
elapses. Returns the Try of the result (moved-out), or throws FutureTimeout exception.
Preconditions:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == false
Definition at line 2185 of file Future-inl.h.
References folly::futures::detail::FutureBase< T >::core_, folly::Future< T >::getTry(), folly::gen::move, and folly::Future< T >::wait().
|
static |
Creates/returns an invalid SemiFuture, that is, one with no shared state.
Postcondition:
RESULT.valid() == false
Definition at line 775 of file Future-inl.h.
Referenced by TEST().
|
delete |
|
noexcept |
Definition at line 833 of file Future-inl.h.
References folly::futures::detail::FutureBase< T >::assign(), folly::futures::detail::FutureBase< T >::core_, and folly::gen::move.
|
noexcept |
Definition at line 840 of file Future-inl.h.
References folly::futures::detail::FutureBase< T >::assign(), folly::futures::detail::FutureBase< T >::core_, folly::gen::move, and folly::futures::detail::FutureBase< T >::setExecutor().
|
staticprivate |
Definition at line 803 of file Future-inl.h.
References folly::futures::detail::FutureBase< T >::detach(), folly::pushmi::executor, folly::futures::detail::Core< T >::getExecutor(), and folly::futures::detail::Core< T >::setExecutor().
|
private |
Definition at line 791 of file Future-inl.h.
References folly::futures::detail::FutureBase< T >::core_, folly::pushmi::executor, folly::futures::detail::FutureBase< T >::getExecutor(), folly::getKeepAliveToken(), and folly::futures::detail::Core< T >::setExecutor().
Referenced by folly::futures::detail::stealDeferredExecutor().
Future< T > folly::SemiFuture< T >::toUnsafeFuture | ( | ) |
Returns a future that completes inline, as if the future had no executor. Intended for porting legacy code without behavioral change, and for rare cases where this is really the intended behavior. Future is unsafe in the sense that the executor it completes on is non-deterministic in the standard case. For new code, or to update code that temporarily uses this, please use via and pass a meaningful executor.
Preconditions:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == false
RESULT.valid() == true
Definition at line 875 of file Future-inl.h.
References folly::InlineExecutor::instance(), and folly::gen::move.
Future< T > folly::SemiFuture< T >::via | ( | Executor * | executor, |
int8_t | priority = Executor::MID_PRI |
||
) |
Returns a Future which will call back on the other side of executor.
Definition at line 870 of file Future-inl.h.
References folly::pushmi::executor, folly::getKeepAliveToken(), and folly::gen::move.
Future< T > folly::SemiFuture< T >::via | ( | Executor::KeepAlive<> | executor, |
int8_t | priority = Executor::MID_PRI |
||
) |
Definition at line 851 of file Future-inl.h.
References folly::futures::detail::FutureBase< T >::core_, folly::pushmi::executor, folly::futures::detail::getDeferredExecutor(), folly::gen::move, and folly::futures::detail::Core< T >::setExecutor().
SemiFuture< T > && folly::SemiFuture< T >::wait | ( | ) |
Blocks the caller's thread until this Future isReady()
, i.e., until the asynchronous producer has stored a result or exception.
Preconditions:
valid() == true
(else throws FutureInvalid)Postconditions:
Definition at line 2106 of file Future-inl.h.
References folly::futures::detail::WaitExecutor::create(), folly::futures::detail::FutureBase< T >::detach(), folly::futures::detail::getDeferredExecutor(), folly::Promise< T >::getSemiFuture(), folly::gen::move, folly::futures::detail::FutureBase< T >::setCallback_(), folly::Future< T >::wait(), and folly::futures::detail::waitImpl().
Referenced by folly::SemiFuture< T >::wait().
SemiFuture<T>&& folly::SemiFuture< T >::wait | ( | ) |
Blocks the caller's thread until this Future isReady()
, i.e., until the asynchronous producer has stored a result or exception.
Preconditions:
valid() == true
(else throws FutureInvalid)Postconditions:
bool folly::SemiFuture< T >::wait | ( | Duration | dur | ) |
Blocks until the future is fulfilled, or dur
elapses. Returns true if the future was fulfilled.
Preconditions:
valid() == true
(else throws FutureInvalid)Postconditions:
valid() == false
Definition at line 2134 of file Future-inl.h.
References folly::futures::detail::WaitExecutor::create(), folly::futures::detail::FutureBase< T >::detach(), folly::futures::detail::getDeferredExecutor(), folly::Promise< T >::getSemiFuture(), folly::gen::move, now(), folly::futures::detail::FutureBase< T >::setCallback_(), folly::SemiFuture< T >::wait(), and folly::futures::detail::waitImpl().
|
private |
Blocks until the future is fulfilled, or dur
elapses.
Preconditions:
valid() == true
(else throws FutureInvalid)Postconditions:
|
inline |
|
inline |
Definition at line 795 of file Future.h.
References folly::coro::co_viaIfAsync(), folly::gen::move, promise_, and folly::value().
|
friend |
|
friend |