Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
util::async::BasicExecutionContext< ContextType, StopSourceType, DispatcherType, TimerContextProvider, ErrorHandlerType > Class Template Reference

A highly configurable execution context. More...

#include <BasicExecutionContext.hpp>

Public Types

using ContextHolderType = ContextType
 
using ExecutorType = typename ContextHolderType::Executor
 
template<typename T >
using ValueType = std::expected<T, ExecutionError>
 
using StopSource = StopSourceType
 
using StopToken = typename StopSourceType::Token
 
template<typename T >
using StoppableOperation = StoppableOperation<ValueType<T>, StopSourceType>
 
template<typename T >
using Operation = Operation<ValueType<T>>
 
using Strand
 
using Timer = typename ContextHolderType::Timer
 
template<typename T >
using ScheduledOperation = ScheduledOperation<BasicExecutionContext, StoppableOperation<T>>
 
using RepeatedOperation = RepeatingOperation<BasicExecutionContext>
 

Public Member Functions

 BasicExecutionContext (std::size_t numThreads=1) noexcept
 Create a new execution context with the given number of threads.
 
 ~BasicExecutionContext ()
 Stops the underlying thread pool.
 
 BasicExecutionContext (BasicExecutionContext &&)=default
 
 BasicExecutionContext (BasicExecutionContext const &)=delete
 
auto scheduleAfter (SomeStdDuration auto delay, SomeHandlerWith< StopToken > auto &&fn, std::optional< std::chrono::milliseconds > timeout=std::nullopt) noexcept(kIS_NOEXCEPT)
 Schedule an operation on the execution context.
 
auto scheduleAfter (SomeStdDuration auto delay, SomeHandlerWith< StopToken, bool > auto &&fn, std::optional< std::chrono::milliseconds > timeout=std::nullopt) noexcept(kIS_NOEXCEPT)
 Schedule an operation on the execution context.
 
auto executeRepeatedly (SomeStdDuration auto interval, SomeHandlerWithoutStopToken auto &&fn) noexcept(kIS_NOEXCEPT)
 Schedule a repeating operation on the execution context.
 
auto execute (SomeHandlerWith< StopToken > auto &&fn, std::optional< std::chrono::milliseconds > timeout=std::nullopt) noexcept(kIS_NOEXCEPT)
 Schedule an operation on the execution context.
 
auto execute (SomeHandlerWith< StopToken > auto &&fn, SomeStdDuration auto timeout) noexcept(kIS_NOEXCEPT)
 Schedule an operation on the execution context.
 
auto execute (SomeHandlerWithoutStopToken auto &&fn) noexcept(kIS_NOEXCEPT)
 Schedule an operation on the execution context.
 
Strand makeStrand ()
 Create a strand for this execution context.
 
void stop () const noexcept
 Stop the execution context as soon as possible.
 
void join () const noexcept
 Block until all operations are completed.
 

Static Public Attributes

static constexpr bool kIS_NOEXCEPT = noexcept(ErrorHandlerType::wrap([](auto&) { throw 0; }))
 Whether operations on this execution context are noexcept.
 

Detailed Description

template<typename ContextType, typename StopSourceType, typename DispatcherType, typename TimerContextProvider = impl::SelfContextProvider, typename ErrorHandlerType = impl::DefaultErrorHandler>
class util::async::BasicExecutionContext< ContextType, StopSourceType, DispatcherType, TimerContextProvider, ErrorHandlerType >

A highly configurable execution context.

This execution context is used as the base for all specialized execution contexts. Return values are handled by capturing them and returning them packaged as std::expected. Exceptions may or may not be caught and handled depending on the error strategy. The default behavior is to catch and package them as the error channel of std::expected.

Member Typedef Documentation

◆ Strand

template<typename ContextType , typename StopSourceType , typename DispatcherType , typename TimerContextProvider = impl::SelfContextProvider, typename ErrorHandlerType = impl::DefaultErrorHandler>
using util::async::BasicExecutionContext< ContextType, StopSourceType, DispatcherType, TimerContextProvider, ErrorHandlerType >::Strand
Initial value:
impl::
BasicStrand<BasicExecutionContext, StopSourceType, DispatcherType, TimerContextProvider, ErrorHandlerType>

Constructor & Destructor Documentation

◆ BasicExecutionContext()

template<typename ContextType , typename StopSourceType , typename DispatcherType , typename TimerContextProvider = impl::SelfContextProvider, typename ErrorHandlerType = impl::DefaultErrorHandler>
util::async::BasicExecutionContext< ContextType, StopSourceType, DispatcherType, TimerContextProvider, ErrorHandlerType >::BasicExecutionContext ( std::size_t numThreads = 1)
inlineexplicitnoexcept

Create a new execution context with the given number of threads.

Parameters
numThreadsThe number of threads to use for the underlying thread pool

Member Function Documentation

◆ execute() [1/3]

template<typename ContextType , typename StopSourceType , typename DispatcherType , typename TimerContextProvider = impl::SelfContextProvider, typename ErrorHandlerType = impl::DefaultErrorHandler>
auto util::async::BasicExecutionContext< ContextType, StopSourceType, DispatcherType, TimerContextProvider, ErrorHandlerType >::execute ( SomeHandlerWith< StopToken > auto && fn,
SomeStdDuration auto timeout )
inlinenodiscardnoexcept

Schedule an operation on the execution context.

Parameters
fnThe block of code to execute with stop token as first arg
timeoutThe timeout duration after which the operation will be cancelled
Returns
A stoppable operation that can be used to wait for the result

◆ execute() [2/3]

template<typename ContextType , typename StopSourceType , typename DispatcherType , typename TimerContextProvider = impl::SelfContextProvider, typename ErrorHandlerType = impl::DefaultErrorHandler>
auto util::async::BasicExecutionContext< ContextType, StopSourceType, DispatcherType, TimerContextProvider, ErrorHandlerType >::execute ( SomeHandlerWith< StopToken > auto && fn,
std::optional< std::chrono::milliseconds > timeout = std::nullopt )
inlinenodiscardnoexcept

Schedule an operation on the execution context.

Parameters
fnThe block of code to execute with stop token as first arg
timeoutThe optional timeout duration after which the operation will be cancelled
Returns
A stoppable operation that can be used to wait for the result

◆ execute() [3/3]

template<typename ContextType , typename StopSourceType , typename DispatcherType , typename TimerContextProvider = impl::SelfContextProvider, typename ErrorHandlerType = impl::DefaultErrorHandler>
auto util::async::BasicExecutionContext< ContextType, StopSourceType, DispatcherType, TimerContextProvider, ErrorHandlerType >::execute ( SomeHandlerWithoutStopToken auto && fn)
inlinenodiscardnoexcept

Schedule an operation on the execution context.

Parameters
fnThe block of code to execute. Signature is Type() where Type is the return type.
Returns
A unstoppable operation that can be used to wait for the result

◆ executeRepeatedly()

template<typename ContextType , typename StopSourceType , typename DispatcherType , typename TimerContextProvider = impl::SelfContextProvider, typename ErrorHandlerType = impl::DefaultErrorHandler>
auto util::async::BasicExecutionContext< ContextType, StopSourceType, DispatcherType, TimerContextProvider, ErrorHandlerType >::executeRepeatedly ( SomeStdDuration auto interval,
SomeHandlerWithoutStopToken auto && fn )
inlinenodiscardnoexcept

Schedule a repeating operation on the execution context.

Parameters
intervalThe interval at which the operation should be repeated
fnThe block of code to execute; no args allowed and return type must be void
Returns
A repeating stoppable operation that can be used to wait for its cancellation

◆ makeStrand()

template<typename ContextType , typename StopSourceType , typename DispatcherType , typename TimerContextProvider = impl::SelfContextProvider, typename ErrorHandlerType = impl::DefaultErrorHandler>
Strand util::async::BasicExecutionContext< ContextType, StopSourceType, DispatcherType, TimerContextProvider, ErrorHandlerType >::makeStrand ( )
inlinenodiscard

Create a strand for this execution context.

Returns
A strand for this execution context

◆ scheduleAfter() [1/2]

template<typename ContextType , typename StopSourceType , typename DispatcherType , typename TimerContextProvider = impl::SelfContextProvider, typename ErrorHandlerType = impl::DefaultErrorHandler>
auto util::async::BasicExecutionContext< ContextType, StopSourceType, DispatcherType, TimerContextProvider, ErrorHandlerType >::scheduleAfter ( SomeStdDuration auto delay,
SomeHandlerWith< StopToken > auto && fn,
std::optional< std::chrono::milliseconds > timeout = std::nullopt )
inlinenodiscardnoexcept

Schedule an operation on the execution context.

Parameters
delayThe delay after which the operation should be executed
fnThe block of code to execute with stop token as the only arg
timeoutThe optional timeout duration after which the operation will be cancelled
Returns
A scheduled stoppable operation that can be used to wait for the result

◆ scheduleAfter() [2/2]

template<typename ContextType , typename StopSourceType , typename DispatcherType , typename TimerContextProvider = impl::SelfContextProvider, typename ErrorHandlerType = impl::DefaultErrorHandler>
auto util::async::BasicExecutionContext< ContextType, StopSourceType, DispatcherType, TimerContextProvider, ErrorHandlerType >::scheduleAfter ( SomeStdDuration auto delay,
SomeHandlerWith< StopToken, bool > auto && fn,
std::optional< std::chrono::milliseconds > timeout = std::nullopt )
inlinenodiscardnoexcept

Schedule an operation on the execution context.

Parameters
delayThe delay after which the operation should be executed
fnThe block of code to execute with stop token as the first arg and cancellation flag as the second arg
timeoutThe optional timeout duration after which the operation will be cancelled
Returns
A scheduled stoppable operation that can be used to wait for the result

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