template<typename Executor, typename OpType>
struct zyppng::LogicBase< Executor, OpType >
Logic base class template, this allows us to implement certain workflows in a sync/async agnostic way, based on the OpType the code is either sync or async:
AsyncOpRef<expected<int>> computeInt( ContextRef context );
expected<int> computeInt( SyncContextRef context );
namespace {
template <
typename Executor
, typename OpType
>
struct ComputeIntLogic :
public LogicBase<Executor, OpType>
{
LogicImpl( ZyppContextRefType ctx )
{}
MaybeAsyncRef<<expected<int>> execute() {
return executor()->computeSomeInt()
| and_then( [this]( int result ) {
std::cout<< "Int calculated as: " << result << std::endl;
return expected<int>::success(result);
});
}
protected:
};
class ComputeIntAsyncExecutor : public ComputeIntLogic<ComputeIntAsyncExecutor, AsyncOp<int>>
{
using ComputeIntLogic<ComputeIntAsyncExecutor, AsyncOp<int>>::ComputeIntLogic;
AsyncOpRef<expected<int>> computeSomeInt() {
}
};
class ComputeIntSyncExecutor : public ComputeIntLogic<ComputeIntAsyncExecutor, SyncOp<int>>
{
using ComputeIntLogic<ComputeIntAsyncExecutor, SyncOp<int>>::ComputeIntLogic;
expected<int> computeSomeInt(){
}
};
}
AsyncOpRef<expected<int>> computeInt( ContextRef context ) {
return ComputeIntAsyncExecutor::run( std::move(context) );
}
expected<int> computeInt( SyncContextRef context ) {
return ComputeIntSyncExecutor::run( std::move(context) );
}
#define ZYPP_ENABLE_LOGIC_BASE(Executor, OpType)
std::conditional_t< detail::is_async_op_v< OpType >, ContextRef, SyncContextRef > MaybeAsyncContextRef
Definition at line 122 of file logichelpers.h.