proxygen
folly::observer::CallbackHandle Class Reference

#include <Observer.h>

Classes

struct  Context
 

Public Member Functions

 CallbackHandle ()
 
template<typename T >
 CallbackHandle (Observer< T > observer, folly::Function< void(Snapshot< T >)> callback)
 
 CallbackHandle (const CallbackHandle &)=delete
 
 CallbackHandle (CallbackHandle &&)=default
 
CallbackHandleoperator= (const CallbackHandle &)=delete
 
CallbackHandleoperator= (CallbackHandle &&)=default
 
 ~CallbackHandle ()
 
void cancel ()
 

Private Attributes

std::shared_ptr< Contextcontext_
 

Detailed Description

Definition at line 121 of file Observer.h.

Constructor & Destructor Documentation

folly::observer::CallbackHandle::CallbackHandle ( )
inline

Definition at line 81 of file Observer-inl.h.

81 {}
template<typename T >
folly::observer::CallbackHandle::CallbackHandle ( Observer< T observer,
folly::Function< void(Snapshot< T >)>  callback 
)

Definition at line 84 of file Observer-inl.h.

References context, folly::observer::makeObserver(), folly::gen::move, and folly::unit.

86  {
87  context_ = std::make_shared<Context>();
88  context_->observer = makeObserver([observer = std::move(observer),
89  callback = std::move(callback),
90  context = context_]() mutable {
91  auto rCanceled = context->canceled.rlock();
92  if (*rCanceled) {
93  return folly::unit;
94  }
95  callback(*observer);
96  return folly::unit;
97  });
98 }
context
Definition: CMakeCache.txt:563
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
std::shared_ptr< Context > context_
Definition: Observer.h:139
Observer< observer_detail::ResultOfUnwrapSharedPtr< F > > makeObserver(F &&creator)
Definition: Observer-inl.h:37
constexpr Unit unit
Definition: Unit.h:45
folly::observer::CallbackHandle::CallbackHandle ( const CallbackHandle )
delete
folly::observer::CallbackHandle::CallbackHandle ( CallbackHandle &&  )
default
folly::observer::CallbackHandle::~CallbackHandle ( )
inline

Definition at line 100 of file Observer-inl.h.

100  {
101  cancel();
102 }

Member Function Documentation

void folly::observer::CallbackHandle::cancel ( )
inline

Definition at line 104 of file Observer-inl.h.

104  {
105  if (!context_) {
106  return;
107  }
108  context_->observer.reset();
109  context_->canceled = true;
110  context_.reset();
111 }
std::shared_ptr< Context > context_
Definition: Observer.h:139
CallbackHandle& folly::observer::CallbackHandle::operator= ( const CallbackHandle )
delete
CallbackHandle& folly::observer::CallbackHandle::operator= ( CallbackHandle &&  )
default

Member Data Documentation

std::shared_ptr<Context> folly::observer::CallbackHandle::context_
private

Definition at line 139 of file Observer.h.


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