proxygen
folly::FutureSplitter< T > Class Template Reference

#include <Future.h>

Public Member Functions

 FutureSplitter ()=default
 
 FutureSplitter (Future< T > &&future)
 
Future< TgetFuture ()
 
SemiFuture< TgetSemiFuture ()
 

Static Private Member Functions

static ExecutorgetExecutorFrom (Future< T > &f)
 

Private Attributes

std::shared_ptr< SharedPromise< T > > promise_
 
Executore_ = nullptr
 
int8_t priority_ {-1}
 

Detailed Description

template<class T>
class folly::FutureSplitter< T >

Definition at line 110 of file Future.h.

Constructor & Destructor Documentation

template<class T>
folly::FutureSplitter< T >::FutureSplitter ( )
default

Default constructor for convenience only. It is an error to call getFuture() on a default-constructed FutureSplitter which has not had a correctly-constructed FutureSplitter copy- or move-assigned into it.

template<class T>
folly::FutureSplitter< T >::FutureSplitter ( Future< T > &&  future)
inlineexplicit

Provide a way to split a Future<T>.

Definition at line 52 of file FutureSplitter.h.

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

53  : promise_(std::make_shared<SharedPromise<T>>()),
54  e_(getExecutorFrom(future)),
55  priority_(future.getPriority()) {
56  std::move(future).thenTry([promise = promise_](Try<T>&& theTry) {
57  promise->setTry(std::move(theTry));
58  });
59  }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::shared_ptr< SharedPromise< T > > promise_
static Executor * getExecutorFrom(Future< T > &f)

Member Function Documentation

template<class T>
static Executor* folly::FutureSplitter< T >::getExecutorFrom ( Future< T > &  f)
inlinestaticprivate

Definition at line 86 of file FutureSplitter.h.

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

86  {
87  // If the passed future had a null executor, use an inline executor
88  // to ensure that .via is safe
89  auto* e = f.getExecutor();
90  return e ? e : &InlineExecutor::instance();
91  }
auto f
FOLLY_ATTR_VISIBILITY_HIDDEN static FOLLY_ALWAYS_INLINE InlineExecutor & instance() noexcept
template<class T>
Future<T> folly::FutureSplitter< T >::getFuture ( )
inline

This can be called an unlimited number of times per FutureSplitter.

Definition at line 64 of file FutureSplitter.h.

References promise_.

Referenced by TEST().

64  {
65  if (promise_ == nullptr) {
66  throw_exception<FutureSplitterInvalid>();
67  }
68  return promise_->getSemiFuture().via(e_, priority_);
69  }
std::shared_ptr< SharedPromise< T > > promise_
template<class T>
SemiFuture<T> folly::FutureSplitter< T >::getSemiFuture ( )
inline

This can be called an unlimited number of times per FutureSplitter.

Definition at line 74 of file FutureSplitter.h.

References promise_.

Referenced by TEST().

74  {
75  if (promise_ == nullptr) {
76  throw_exception<FutureSplitterInvalid>();
77  }
78  return promise_->getSemiFuture();
79  }
std::shared_ptr< SharedPromise< T > > promise_

Member Data Documentation

template<class T>
Executor* folly::FutureSplitter< T >::e_ = nullptr
private

Definition at line 83 of file FutureSplitter.h.

template<class T>
int8_t folly::FutureSplitter< T >::priority_ {-1}
private

Definition at line 84 of file FutureSplitter.h.

template<class T>
std::shared_ptr<SharedPromise<T> > folly::FutureSplitter< T >::promise_
private

Definition at line 82 of file FutureSplitter.h.


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