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

Driver that turns a coroutine factory into a latest-wins async validation rule attached to a Validator<T>. More...

#include <async_validator.hpp>

Public Types

using Factory = typename detail::AsyncValidatorState<T>::Factory

Public Member Functions

 AsyncValidator (IExecutor &ui, IExecutor &worker, Factory factory)
 ~AsyncValidator ()
 AsyncValidator (const AsyncValidator &)=delete
AsyncValidatoroperator= (const AsyncValidator &)=delete
 AsyncValidator (AsyncValidator &&) noexcept=default
AsyncValidatoroperator= (AsyncValidator &&other) noexcept
::aria::Subscription attach_to (::aria::Validator< T > &v, ::aria::Property< T > &source)
 Attach to a Validator + its source Property.

Detailed Description

template<class T>
class aria::async::AsyncValidator< T >

Driver that turns a coroutine factory into a latest-wins async validation rule attached to a Validator<T>.

Typical usage:

AsyncValidator<std::string> av{
    ui_executor, worker_pool,
    [&](std::string username, CancellationToken tok)
        -> Task<AsyncRuleResult> {
        tok.throw_if_cancelled();
        bool taken = co_await api.check_username(username);
        tok.throw_if_cancelled();
        if (taken) {
            co_return AsyncRuleResult::failed(
                ValidationKey{"signup.username", "remote_taken"},
                "Username already taken");
        }
        co_return AsyncRuleResult::passed();
    }};
Subscription sub = av.attach_to(validator, source_property);

On every change of source_property the AsyncValidator cancels the previous rule, fires a new one, and surfaces the result via validator.begin_pending() / end_pending(...). Attach, detach, move assignment and destruction run on the graph thread. Both executors must outlive their queued coroutine work.

Member Typedef Documentation

◆ Factory

template<class T>
using aria::async::AsyncValidator< T >::Factory = typename detail::AsyncValidatorState<T>::Factory

Constructor & Destructor Documentation

◆ AsyncValidator() [1/3]

template<class T>
aria::async::AsyncValidator< T >::AsyncValidator ( IExecutor & ui,
IExecutor & worker,
Factory factory )
inline

◆ ~AsyncValidator()

template<class T>
aria::async::AsyncValidator< T >::~AsyncValidator ( )
inline

◆ AsyncValidator() [2/3]

template<class T>
aria::async::AsyncValidator< T >::AsyncValidator ( const AsyncValidator< T > & )
delete

◆ AsyncValidator() [3/3]

template<class T>
aria::async::AsyncValidator< T >::AsyncValidator ( AsyncValidator< T > && )
defaultnoexcept

Member Function Documentation

◆ operator=() [1/2]

template<class T>
AsyncValidator & aria::async::AsyncValidator< T >::operator= ( const AsyncValidator< T > & )
delete

◆ operator=() [2/2]

template<class T>
AsyncValidator & aria::async::AsyncValidator< T >::operator= ( AsyncValidator< T > && other)
inlinenoexcept

◆ attach_to()

template<class T>
::aria::Subscription aria::async::AsyncValidator< T >::attach_to ( ::aria::Validator< T > & v,
::aria::Property< T > & source )
inlinenodiscard

Attach to a Validator + its source Property.

The returned Subscription owns the lifetime: destroying it detaches the validator and cancels any in-flight rule (V-6).


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