libzypp 17.37.17
await.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8----------------------------------------------------------------------/
9*
10* This file contains private API, this might break at any time between releases.
11* You have been warned!
12*
13*/
14#ifndef ZYPPNG_MONADIC_AWAIT_H_INCLUDED
15#define ZYPPNG_MONADIC_AWAIT_H_INCLUDED
16
17
18#include <zypp-core/zyppng/pipelines/AsyncResult>
19#include <zypp-core/zyppng/base/Signals>
20
21namespace zyppng {
22
23 namespace detail
24 {
25 template <typename T, typename SigGetter> struct AwaitImpl;
26
27 template <typename ArgType, typename SigR, typename ...SigT >
28 struct AwaitImpl<ArgType, SignalProxy<SigR(SigT...)> (ArgType::*)()> : public zyppng::AsyncOp< std::shared_ptr<ArgType> > {
29
30 using SigGetter = SignalProxy<SigR(SigT...)> (ArgType::*)();
31
32 template<typename S>
33 AwaitImpl ( S&& sigGet ) : _sigGet( std::forward<S>(sigGet ) ) {}
34
35 virtual ~AwaitImpl(){ }
36
37 void operator() ( std::shared_ptr<ArgType> &&req ) {
38 _req = std::move(req);
39 std::invoke( _sigGet, _req ).connect( sigc::mem_fun(this, &AwaitImpl::sigHandler<SigR>) );
40 }
41
42 private:
43 template < typename RetType = SigR >
45 sigHandler ( SigT... ) {
46 this->setReady( std::move(_req) );
47 }
48
49 template < typename RetType = SigR >
51 sigHandler ( SigT... ) {
52 this->setReady( std::move(_req) );
53 return {};
54 }
55
56 std::shared_ptr<ArgType> _req;
58 };
59 }
60
61 //return a async op that waits for a signal to emitted by a object
62 template <typename T,
63 typename SignalGetter >
64 auto await ( SignalGetter &&sigGet )
65 {
66 return std::make_shared<detail::AwaitImpl<T, SignalGetter>>( std::forward<SignalGetter>(sigGet) );
67 }
68
69}
70
71#endif
bool operator()(const zypp::Arch &lhs, const zypp::Arch &rhs) const
Default order for std::container based Arch::compare.
Definition Arch.h:370
Definition Arch.h:364
typename enable_if< B, T >::type enable_if_t
Definition TypeTraits.h:45
std::enable_if< std::is_member_pointer< typenamestd::decay< Functor >::type >::value, typenamestd::result_of< Functor &&(Args &&...)>::type >::type invoke(Functor &&f, Args &&... args)
Definition functional.h:32
auto await(SignalGetter &&sigGet)
Definition await.h:64
std::enable_if_t< std::is_same_v< void, RetType >, RetType > sigHandler(SigT...)
Definition await.h:45
std::enable_if_t< !std::is_same_v< void, RetType >, RetType > sigHandler(SigT...)
Definition await.h:51