MEL
Microthread & Execution library
mel::execution Namespace Reference

High level execution utilities. More...

Namespaces

 flow
 Functions for flow management.
 

Classes

struct  VoidType
 Empty type used in some cases when a type is needed to represent a void. More...
 
struct  WrapperType
 
struct  WrapperType< void >
 
class  Executor
 
struct  ExecutorTraits
 Default traits for any executor. More...
 
class  OnAllException
 Excepcion thrown by on_all when some of the futures raise error. More...
 
class  ExFuture
 Extension of mel::core::Future to apply to executors. More...
 
struct  InlineExecutionAgent
 
class  Executor< InlineExecutionAgent >
 Executor specialization using InlineExecutionAgent as execution agent. More...
 
struct  ExecutorTraits< Executor< InlineExecutionAgent > >
 Executor Traits for InlineExecutionAgent Executor. More...
 
struct  NaiveInlineExecutionAgent
 
class  Executor< NaiveInlineExecutionAgent >
 Executor specialization using NaiveInlineExecutionAgent as execution agent. More...
 
struct  ExecutorTraits< Executor< NaiveInlineExecutionAgent > >
 Executor Traits for NaiveInlineExecutionAgent Executor. More...
 
struct  RunnableExecutorOpts
 Concrete options for this type of executor. More...
 
class  Executor< Runnable >
 Executor specialization using Runnable as execution agent. More...
 
struct  ExecutorTraits< Executor< Runnable > >
 Executor Traits for Runnable Executor. More...
 
struct  ThreadPoolExecutorOpts
 Concrete options for this type of executor. More...
 
class  Executor< ThreadPool >
 Executor specialization using a ThreadPool as execution agent. More...
 
struct  ExecutorTraits< Executor< ThreadPool > >
 Executor Traits for ThreadPool Executor. More...
 

Typedefs

typedef Executor< InlineExecutionAgentInlineExecutor
 alias for Executor<InlineExecutionAgent>
 
typedef Executor< NaiveInlineExecutionAgentNaiveInlineExecutor
 alias for Executor<NaiveInlineExecutionAgent>
 
typedef Executor< RunnableRunnableExecutor
 alias for Executor<Runnable>
 
typedef Executor< ThreadPool > ThreadPoolExecutor
 alias for Executor<ThreadPool>
 

Functions

template<class F , class ExecutorAgent >
ExFuture< ExecutorAgent, std::invoke_result_t< F > > launch (Executor< ExecutorAgent > ex, F &&f)
 Launch given functor in given executor. More...
 
template<class TArg , class F , class ExecutorAgent >
ExFuture< ExecutorAgent, std::invoke_result_t< F, TArg > > launch (Executor< ExecutorAgent > ex, F &&f, TArg &&arg)
 Launch given functor in given executor, passing it input parameter. More...
 
template<class ExecutorAgent >
ExFuture< ExecutorAgent, void > start (Executor< ExecutorAgent > ex)
 Start a chain of execution in given executor. More...
 
template<class ExecutorAgent , class TArg , class TRet >
ExFuture< ExecutorAgent, typename std::remove_cv< typename std::remove_reference< TRet >::type >::type > inmediate (ExFuture< ExecutorAgent, TArg > fut, TRet &&arg)
 Produces an inmediate value in the context of the given ExFuture executor as a response to input fut completion If input fut has error, the this error is forwarded to inmediate result.
 
template<class F , class TArg , class ExecutorAgent >
ExFuture< ExecutorAgent, std::invoke_result_t< F, TArg > > next (ExFuture< ExecutorAgent, TArg > source, F f)
 Attach a functor to execute when input fut is complete Given functor will be executed inf the input ExFuture executor. input parameter is always pass as reference. More...
 
template<class NewExecutorAgent , class OldExecutorAgent , class TRet >
ExFuture< NewExecutorAgent, TRet > transfer (ExFuture< OldExecutorAgent, TRet > source, Executor< NewExecutorAgent > newAgent)
 Transfer given ExFuture to a different executor This way, continuations can be chained but executed in diferent executors.
 
template<class ExecutorAgent , class TArg , class I , class F >
ExFuture< ExecutorAgent, TArg > loop (ExFuture< ExecutorAgent, TArg > source, I getIteratorsFunc, F functor, int increment=1)
 parallel (possibly, depending on executor capabilities) loop More...
 
template<class ExecutorAgent , class TArg , class... FTypes>
ExFuture< ExecutorAgent, TArg > parallel (ExFuture< ExecutorAgent, TArg > source, FTypes... functions)
 Execute given functions in a (possibly, depending on concrete executor) parallel way If an exception is thrown in any of the callables, and noexcept is no specified, the value of the first exception thrown is set as error in the resulting future, so forwarding the error to the next element (if any) of the chain. More...
 
template<class F , class TArg , class ExecutorAgent >
ExFuture< ExecutorAgent, TArg > catchError (ExFuture< ExecutorAgent, TArg > source, F &&f)
 Capture previous error, if any, and execute the function. More...
 
template<class TArg , class ExecutorAgent , class... FTypes>
ExFuture< ExecutorAgent, typename ::mel::execution::_private::GetReturn< TArg, FTypes... >::type > parallel_convert (ExFuture< ExecutorAgent, TArg > source, FTypes... functions)
 Same as parallel but returning a tuple with the values for each functor. More...
 
template<class F , class TArg , class ExecutorAgent >
ExFuture< ExecutorAgent, std::invoke_result_t< F, Executor< ExecutorAgent >, TArg > > getExecutor (ExFuture< ExecutorAgent, TArg > source, F f)
 Get the Executor used in the chain of execution. More...
 
template<class TRet >
_private::ApplyInmediate< TRet > inmediate (TRet &&arg)
 
template<class NewExecutionAgent >
_private::ApplyTransfer< NewExecutionAgent > transfer (Executor< NewExecutionAgent > newAgent)
 Version for use with operator |.
 
template<class F >
_private::ApplyNext< F > next (F &&f)
 version for use with operator |
 
template<class I , class F >
_private::ApplyLoop< I, F > loop (I &&getItFunc, F &&functor, int increment=1)
 version for use with operator |
 
template<class... FTypes>
_private::ApplyBulk< FTypes... > parallel (FTypes &&... functions)
 version for use with operator |
 
template<class F >
_private::ApplyError< F > catchError (F &&f)
 version for use with operator |
 
template<class... FTypes>
_private::ApplyParallelConvert< FTypes... > parallel_convert (FTypes &&... functions)
 version for use with operator |
 
template<class F >
_private::ApplyGetExecutor< F > getExecutor (F &&f)
 version for use with operator |
 
template<class ExecutorAgent , class TRet1 , class U >
auto operator| (const ExFuture< ExecutorAgent, TRet1 > &input, U &&u)
 overload operator | for chaining
 
template<class ExecutorAgent , class TRet1 , class U >
auto operator| (ExFuture< ExecutorAgent, TRet1 > &&input, U &&u)
 
template<class ExecutorAgent , class... FTypes>
auto on_all (Executor< ExecutorAgent > ex, FTypes... futs)
 return ExFuture which will be executed, in the context of the given executor ex, when all the given ExFutures are triggered. More...
 
template<class TArg , class I , class F >
ExFuture< InlineExecutionAgent, TArg > loop (ExFuture< InlineExecutionAgent, TArg > source, I &&getIteratorsFunc, F &&functor, int increment=1)
 
template<class I , class F >
ExFuture< InlineExecutionAgent, void > loop (ExFuture< InlineExecutionAgent, void > source, I &&getIteratorsFunc, F &&functor, int increment=1)
 
template<class TArg , class... FTypes>
ExFuture< InlineExecutionAgent, TArg > parallel (ExFuture< InlineExecutionAgent, TArg > source, FTypes &&... functions)
 
template<class TArg , class... FTypes>
ExFuture< InlineExecutionAgent, typename mel::execution::_private::GetReturn< TArg, FTypes... >::type > parallel_convert (ExFuture< InlineExecutionAgent, TArg > source, FTypes &&... functions)
 
template<class F >
ExFuture< InlineExecutionAgent, std::invoke_result_t< F > > launch (Executor< InlineExecutionAgent > ex, F &&f)
 Launch given functor in given executor. More...
 
template<class TArg , class F >
ExFuture< InlineExecutionAgent, std::invoke_result_t< F, TArg > > launch (Executor< InlineExecutionAgent > ex, F &&f, TArg &&arg)
 Launch given functor in given executor, passing it input parameter. More...
 
template<class F , class TArg >
ExFuture< InlineExecutionAgent, std::invoke_result_t< F, TArg > > next (ExFuture< InlineExecutionAgent, TArg > source, F &&f)
 
template<class F >
ExFuture< InlineExecutionAgent, std::invoke_result_t< F > > next (ExFuture< InlineExecutionAgent, void > source, F &&f)
 
template<class TArg , class TRet >
ExFuture< InlineExecutionAgent, typename std::remove_cv< typename std::remove_reference< TRet >::type >::type > inmediate (ExFuture< InlineExecutionAgent, TArg > fut, TRet &&arg)
 

Detailed Description

High level execution utilities.

This namespace contains class, functions..to give a consistent execution interface independent of the underliying execution system See Execution System for detailed explanations and examples

Function Documentation

◆ catchError()

template<class F , class TArg , class ExecutorAgent >
ExFuture<ExecutorAgent, TArg> mel::execution::catchError ( ExFuture< ExecutorAgent, TArg >  source,
F &&  f 
)

Capture previous error, if any, and execute the function.

This function works similar to next, but receiving an std::exception_ptr as the parameter and must return same type as input future if no error was raised in previous works of the chain, the function is not executed

◆ getExecutor()

template<class F , class TArg , class ExecutorAgent >
ExFuture<ExecutorAgent, std::invoke_result_t<F, Executor<ExecutorAgent>, TArg> > mel::execution::getExecutor ( ExFuture< ExecutorAgent, TArg >  source,
f 
)

Get the Executor used in the chain of execution.

Given callable gets current executor and the previous value and return The intent of function is to be able to check executor traits or change some option in it

Parameters
[in]fCallable with signature void (auto executor)
See also
ExecutorTraits

◆ launch() [1/4]

template<class F , class ExecutorAgent >
ExFuture<ExecutorAgent, std::invoke_result_t<F> > mel::execution::launch ( Executor< ExecutorAgent >  ex,
F &&  f 
)

Launch given functor in given executor.

Returns
ExFuture with return type of function

◆ launch() [2/4]

template<class TArg , class F , class ExecutorAgent >
ExFuture<ExecutorAgent, std::invoke_result_t<F, TArg> > mel::execution::launch ( Executor< ExecutorAgent >  ex,
F &&  f,
TArg &&  arg 
)

Launch given functor in given executor, passing it input parameter.

Returns
ExFuture with return type of function

◆ launch() [3/4]

template<class F >
ExFuture<InlineExecutionAgent, std::invoke_result_t<F> > mel::execution::launch ( Executor< InlineExecutionAgent ex,
F &&  f 
)

Launch given functor in given executor.

Returns
ExFuture with return type of function

◆ launch() [4/4]

template<class TArg , class F >
ExFuture<InlineExecutionAgent, std::invoke_result_t<F, TArg> > mel::execution::launch ( Executor< InlineExecutionAgent ex,
F &&  f,
TArg &&  arg 
)

Launch given functor in given executor, passing it input parameter.

Returns
ExFuture with return type of function

◆ loop()

template<class ExecutorAgent , class TArg , class I , class F >
ExFuture<ExecutorAgent, TArg> mel::execution::loop ( ExFuture< ExecutorAgent, TArg >  source,
getIteratorsFunc,
functor,
int  increment = 1 
)

parallel (possibly, depending on executor capabilities) loop

Note
concrete executor must provide a member loop function with neccesary interface
Parameters
getIteratorsFunccallable with signature std::array<It,2> f(TArg) returning the begin and end iterators to use in the loop
Returns
A ExFuture with same value as input future, whose content IS MOVED

◆ next()

template<class F , class TArg , class ExecutorAgent >
ExFuture<ExecutorAgent, std::invoke_result_t<F, TArg> > mel::execution::next ( ExFuture< ExecutorAgent, TArg >  source,
f 
)

Attach a functor to execute when input fut is complete Given functor will be executed inf the input ExFuture executor. input parameter is always pass as reference.

Returns
An ExFuture with type given by functor result.

◆ on_all()

template<class ExecutorAgent , class... FTypes>
auto mel::execution::on_all ( Executor< ExecutorAgent >  ex,
FTypes...  futs 
)

return ExFuture which will be executed, in the context of the given executor ex, when all the given ExFutures are triggered.

The resulting ExFuture has a std::tuple with the types if the given ExFutures in the same order. If any of the jobs returns void, its result is substituted for VoidType If any of the given input ExFuture has error, the returned one will have the same error indicating the element who failed

Exceptions
OnAllExceptionif any error

◆ parallel()

template<class ExecutorAgent , class TArg , class... FTypes>
ExFuture<ExecutorAgent, TArg> mel::execution::parallel ( ExFuture< ExecutorAgent, TArg >  source,
FTypes...  functions 
)

Execute given functions in a (possibly, depending on concrete executor) parallel way If an exception is thrown in any of the callables, and noexcept is no specified, the value of the first exception thrown is set as error in the resulting future, so forwarding the error to the next element (if any) of the chain.

Returns
A ExFuture with same value as input future, whose content IS MOVED

◆ parallel_convert()

template<class TArg , class ExecutorAgent , class... FTypes>
ExFuture<ExecutorAgent, typename ::mel::execution::_private::GetReturn< TArg, FTypes...>::type> mel::execution::parallel_convert ( ExFuture< ExecutorAgent, TArg >  source,
FTypes...  functions 
)

Same as parallel but returning a tuple with the values for each functor.

functors returning a void will be converted to _private::VoidType. Until 10 callables can be used

Returns
A tuple with types for each functor return, in order. Returning void is not allowed
Note
The limit in callables is because a bug in gcc < 10.2 where template overload resolution is buggy

◆ start()

template<class ExecutorAgent >
ExFuture<ExecutorAgent, void> mel::execution::start ( Executor< ExecutorAgent >  ex)

Start a chain of execution in given executor.

Template Parameters
ExecutorAgent
Parameters
ex
Returns
ExFuture<ExecutorAgent,void>