Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
Loading...
Searching...
No Matches
aria::async::AsyncCommand< R, Args > Class Template Reference

#include <async_command.hpp>

Public Types

using Action = typename Core::Action

Public Member Functions

template<typename Ui, typename Worker, typename Fn>
requires (detail::CancellableAction<Fn, Args...> || detail::PlainAction<Fn, Args...>) && std::is_base_of_v<IExecutor, Ui> &&
std::is_base_of_v<IExecutor, Worker> && (!std::is_same_v<Ui, IExecutor> || !std::is_same_v<Worker, IExecutor>)
 AsyncCommand (Ui &ui, Worker &worker, Fn action, AsyncCommandPolicy policy=AsyncCommandPolicy::Parallel)
 Construct with a "plain" or "cancellable" action.
template<typename Fn>
requires detail::CancellableAction<Fn, Args...> || detail::PlainAction<Fn, Args...>
 AsyncCommand (IExecutor &ui, IExecutor &worker, Fn action, AsyncCommandPolicy policy=AsyncCommandPolicy::Parallel)
 Type-erased overload — the choice for ViewModels that receive IExecutor& from a DI container.
 ~AsyncCommand ()
 AsyncCommand (const AsyncCommand &)=delete
AsyncCommandoperator= (const AsyncCommand &)=delete
void execute (Args... args)
 Fire-and-forget.
Task< AsyncCommandResult< R > > co_execute (Args... args)
 Awaitable version: caller co_awaits a structured result.
AsyncCommandPolicy policy () const noexcept

Public Attributes

Property< bool > & is_executing
Property< std::optional<::aria::Error > > & last_error
Property< std::string > & last_error_message
Property< std::optional< R > > & last_result

Member Typedef Documentation

◆ Action

template<typename R, typename... Args>
using aria::async::AsyncCommand< R, Args >::Action = typename Core::Action

Constructor & Destructor Documentation

◆ AsyncCommand() [1/3]

template<typename R, typename... Args>
template<typename Ui, typename Worker, typename Fn>
requires (detail::CancellableAction<Fn, Args...> || detail::PlainAction<Fn, Args...>) && std::is_base_of_v<IExecutor, Ui> &&
std::is_base_of_v<IExecutor, Worker> && (!std::is_same_v<Ui, IExecutor> || !std::is_same_v<Worker, IExecutor>)
aria::async::AsyncCommand< R, Args >::AsyncCommand ( Ui & ui,
Worker & worker,
Fn action,
AsyncCommandPolicy policy = AsyncCommandPolicy::Parallel )
inline

Construct with a "plain" or "cancellable" action.

The shape is detected at compile time; if you pass a (Args...) callable, we synthesise a wrapper that discards the token. If your callable is ambiguous (happens with generic lambdas), cast it to the desired std::function first.

Executor safety is enforced as eagerly as possible:

  • If the static types of ui and worker are concrete subclasses of IExecutor, this template overload picks them up and rejects unsafe combinations at compile time via the static_asserts below.
  • If ui / worker are IExecutor&, the dedicated overload below performs the equivalent check at construction time.

◆ AsyncCommand() [2/3]

template<typename R, typename... Args>
template<typename Fn>
requires detail::CancellableAction<Fn, Args...> || detail::PlainAction<Fn, Args...>
aria::async::AsyncCommand< R, Args >::AsyncCommand ( IExecutor & ui,
IExecutor & worker,
Fn action,
AsyncCommandPolicy policy = AsyncCommandPolicy::Parallel )
inline

Type-erased overload — the choice for ViewModels that receive IExecutor& from a DI container.

◆ ~AsyncCommand()

template<typename R, typename... Args>
aria::async::AsyncCommand< R, Args >::~AsyncCommand ( )
inline

◆ AsyncCommand() [3/3]

template<typename R, typename... Args>
aria::async::AsyncCommand< R, Args >::AsyncCommand ( const AsyncCommand< R, Args > & )
delete

Member Function Documentation

◆ operator=()

template<typename R, typename... Args>
AsyncCommand & aria::async::AsyncCommand< R, Args >::operator= ( const AsyncCommand< R, Args > & )
delete

◆ execute()

template<typename R, typename... Args>
void aria::async::AsyncCommand< R, Args >::execute ( Args... args)
inline

Fire-and-forget.

Concurrency shape controlled by policy_. Errors are reported via the installed error_sink_ and the observable last_error Property; this function itself is noexcept-by-design (the wrapper coroutine cannot propagate).

◆ co_execute()

template<typename R, typename... Args>
Task< AsyncCommandResult< R > > aria::async::AsyncCommand< R, Args >::co_execute ( Args... args)
inline

Awaitable version: caller co_awaits a structured result.

Never throws. All four invocation outcomes — Completed, Dropped (policy=DropIfRunning while busy), Cancelled (OperationCancelled at any cancellation point), Failed (action threw any other exception) — are folded into the returned AsyncCommandResult. Callers branch on .completed() / .dropped() / .cancelled() / .failed() instead of writing try { co_await ... } catch (...) boilerplate around every invocation site.

◆ policy()

template<typename R, typename... Args>
AsyncCommandPolicy aria::async::AsyncCommand< R, Args >::policy ( ) const
inlinenodiscardnoexcept

Member Data Documentation

◆ is_executing

template<typename R, typename... Args>
Property<bool>& aria::async::AsyncCommand< R, Args >::is_executing

◆ last_error

template<typename R, typename... Args>
Property<std::optional<::aria::Error> >& aria::async::AsyncCommand< R, Args >::last_error

◆ last_error_message

template<typename R, typename... Args>
Property<std::string>& aria::async::AsyncCommand< R, Args >::last_error_message

◆ last_result

template<typename R, typename... Args>
Property<std::optional<R> >& aria::async::AsyncCommand< R, Args >::last_result

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