libzypp: zyppng::AsyncOp< Result > Class Template Reference

libzypp 17.36.6

Public Types | Public Member Functions | Private Attributes | List of all members
zyppng::AsyncOp< Result > Class Template Reference

`#include <zypp-core/zyppng/async/asyncop.h>`

Inheritance diagram for zyppng::AsyncOp< Result >:

## Public Types
using | value_type = Result
using | Ptr = std::shared_ptr<AsyncOp<Result>>
Public Types inherited from zyppng::Base
using | Ptr = std::shared_ptr<Base>
using | WeakPtr = std::weak_ptr<Base>

## Public Member Functions
| AsyncOp ()=default
| AsyncOp (const AsyncOp &other)=delete
AsyncOp & | operator= (const AsyncOp &other)=delete
AsyncOp & | operator= (AsyncOp &&other) noexcept=default
| AsyncOp (AsyncOp &&other) noexcept=default
| ~AsyncOp () override
void | setReady (value_type &&val)
bool | isReady () const
template<typename Fun>
void | onReady (Fun &&cb)
value_type & | get ()
Public Member Functions inherited from zyppng::AsyncOpBase
virtual bool | canCancel ()
virtual void | cancel ()
SignalProxy< void()> | sigStarted ()
SignalProxy< void(const std::string &, int, int)> | sigProgress ()
SignalProxy< void()> | sigReady ()
Public Member Functions inherited from zyppng::Base
| Base ()
virtual | ~Base ()
WeakPtr | parent () const
void | addChild (const Base::Ptr &child)
void | removeChild (const Ptr &child)
const std::unordered_set< Ptr > & | children () const
std::thread::id | threadId () const
template<typename T>
std::vector< std::weak_ptr< T > > | findChildren () const
template<typename T>
std::shared_ptr< T > | shared_this () const
template<typename T>
std::shared_ptr< T > | shared_this ()
template<typename T>
std::weak_ptr< T > | weak_this () const
template<typename T>
std::weak_ptr< T > | weak_this ()
template<typename SenderFunc, typename ReceiverFunc>
auto | connect (SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker>
std::enable_if_t< std::is_member_function_pointer_v< SenderFunc >, connection > | connectFunc (SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)

## Private Attributes
std::function< void(value_type &&)> | _readyCb
std::optional< value_type > | _maybeValue

## Additional Inherited Members
Static Public Member Functions inherited from zyppng::Base
template<typename Obj, typename Functor>
static decltype(auto) | make_base_slot (Obj *o, Functor &&f)
template<typename SenderFunc, typename ReceiverFunc>
static auto | connect (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, typename internal::MemberFunction< ReceiverFunc >::ClassType &recv, ReceiverFunc &&rFunc)
template<typename SenderFunc, typename ReceiverFunc, typename ... Tracker>
static auto | connectFunc (typename internal::MemberFunction< SenderFunc >::ClassType &s, SenderFunc &&sFun, ReceiverFunc &&rFunc, const Tracker &...trackers)
Protected Member Functions inherited from zyppng::Base
| Base (BasePrivate &dd)
Protected Attributes inherited from zyppng::AsyncOpBase
Signal< void()> | _sigStarted
Signal< void()> | _sigReady
Signal< void(const std::string &, int, int)> | _sigProgress
Protected Attributes inherited from zyppng::Base
std::unique_ptr< BasePrivate > | d_ptr

## Detailed Description

template<typename Result>
class zyppng::AsyncOp< Result >

The AsyncOp template class is the basic building block for the asynchronous pipelines. Its the base for all async callbacks as well as the async result type. That basically means every pipeline is just a AsyncOp that contains all previous operations that were defined in the pipeline.

When implementing a async operation that is to be used in a pipeline it is required to add a operator() to the class taking the input parameter. After the operation is finished the implementation must call setReady(). Calling setReady() must be treated like calling return in a normal function and not execute anymore code on the AsyncOp instance afterwards, since the next operation in the pipeline is allowed to free the previous operation as soon as it gets ready.

In case no next operation is defined on the AsyncOp ( when the instance is used as result object ) the return value is cached internally and can be retrieved with

See also
  get().

A async operation can be cancelled by releasing the result object ( the resulting combinatory object ), this will destroy all previous operations that are either running or pending as well. The destructors MUST NOT call setReady() but only release currently running operations.

Definition at line 161 of file asyncop.h.

## Member Typedef Documentation

## ◆ value_type

template<typename Result>

using zyppng::AsyncOp< Result >::value_type = Result

Definition at line 165 of file asyncop.h.

## ◆ Ptr

template<typename Result>

using zyppng::AsyncOp< Result >::Ptr = std::shared_ptr<AsyncOp<Result>>

Definition at line 166 of file asyncop.h.

## Constructor & Destructor Documentation

## ◆ AsyncOp() [1/3]

template<typename Result>

zyppng::AsyncOp< Result >::AsyncOp | ( |  | ) |
| default

## ◆ AsyncOp() [2/3]

template<typename Result>

zyppng::AsyncOp< Result >::AsyncOp | ( | const AsyncOp< Result > & | other | ) |
| delete

## ◆ AsyncOp() [3/3]

template<typename Result>

zyppng::AsyncOp< Result >::AsyncOp | ( | AsyncOp< Result > && | other | ) |
| defaultnoexcept

## ◆ ~AsyncOp()

template<typename Result>

zyppng::AsyncOp< Result >::~AsyncOp | ( |  | ) |
| inlineoverride

Definition at line 176 of file asyncop.h.

## Member Function Documentation

## ◆ operator=() [1/2]

template<typename Result>

AsyncOp & zyppng::AsyncOp< Result >::operator= | ( | const AsyncOp< Result > & | other | ) |
| delete

## ◆ operator=() [2/2]

template<typename Result>

AsyncOp & zyppng::AsyncOp< Result >::operator= | ( | AsyncOp< Result > && | other | ) |
| defaultnoexcept

## ◆ setReady()

template<typename Result>

void zyppng::AsyncOp< Result >::setReady | ( | value_type && | val | ) |
| inline

Sets the async operation ready, in case a callback is registered the val is directly forwarded without storing it.

Definition at line 183 of file asyncop.h.

## ◆ isReady()

template<typename Result>

bool zyppng::AsyncOp< Result >::isReady | ( |  | ) | const
| inline

Checks if the async operation already has finished.

Note
  This can only be used when no callback is registered.

Definition at line 202 of file asyncop.h.

## ◆ onReady()

template<typename Result>
template<typename Fun>

void zyppng::AsyncOp< Result >::onReady | ( | Fun && | cb | ) |
| inline

Registeres a callback that is immediately called when the object gets into ready state. In case the object is in ready state when registering the callback it is called right away.

Note
  this will disable the emitting of sigReady() so it should be only used by the pipeline implementation
  the callback is removed from the AsyncOp after it was executed when the AsyncOp becomes ready

Definition at line 218 of file asyncop.h.

## ◆ get()

template<typename Result>

value_type & zyppng::AsyncOp< Result >::get | ( |  | ) |
| inline

Returns the internally cached value if there is one.

Exceptions

  AsyncOpNotReadyException | if called before the operation is ready

Definition at line 242 of file asyncop.h.

## Member Data Documentation

## ◆ _readyCb

template<typename Result>

std::function<void(value_type &&)> zyppng::AsyncOp< Result >::_readyCb
| private

Definition at line 249 of file asyncop.h.

## ◆ _maybeValue

template<typename Result>

std::optional<value_type> zyppng::AsyncOp< Result >::_maybeValue
| private

Definition at line 250 of file asyncop.h.

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

- zypp-core/zyppng/async/asyncop.h