|
Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
|
#include <async_resource.hpp>
Public Types | |
| using | Fetcher = std::function<Task<T>(Key)> |
Public Member Functions | |
| AsyncResource (IExecutor &ui, IExecutor &worker, Fetcher fetcher) | |
| ~AsyncResource () | |
| AsyncResource (const AsyncResource &)=delete | |
| AsyncResource & | operator= (const AsyncResource &)=delete |
| void | fetch (Key key) |
| Fetch for key. | |
| void | refresh () |
| void | invalidate () noexcept |
| void | clear () |
| void | cancel () |
| Cancel any in-flight fetch and drop its pending write-back, WITHOUT destroying the resource. | |
| bool | has_data () const |
Public Attributes | |
| Property< bool > & | is_loading |
| Property< std::optional<::aria::Error > > & | error |
| Property< std::string > & | error_message |
| Property< std::optional< T > > & | data |
| Property<::aria::Loadable< T > > & | loadable |
| Five-state loadable view-model – Idle / Loading /
Refreshing / Success / Error. | |
| using aria::async::AsyncResource< T, Key >::Fetcher = std::function<Task<T>(Key)> |
|
inline |
|
inline |
|
delete |
|
delete |
|
inline |
Fetch for key.
If the same key already has fresh data and no invalidate() has been called since, this is a no-op. If a fetch for the same key is already in-flight, it's deduped.
|
inline |
|
inlinenoexcept |
|
inline |
|
inline |
Cancel any in-flight fetch and drop its pending write-back, WITHOUT destroying the resource.
This is the third lifetime axis from the cancellation model (see docs/reference/lifecycle.md L-38 and ROADMAP P1-H): wire it to a view-destroy hook so navigating away mid-request stops the coroutine from resuming against a dead view.
AsyncResource<UserProfile> profile{ui, net, fetch};
engine.bind_view_lifetime(view, [&profile]{ profile.cancel(); });
Stale-while-revalidate is preserved: the last successful data is kept (only the loading flag is cleared), so a re-mounted view still renders the previous value while a fresh fetch()/refresh() runs. The resource remains fully usable afterwards — a cancelled CancellationSource stays cancelled forever, so we re-arm a fresh one here.
Thread: must be called on the graph thread (it writes the observable Properties), exactly like clear() / fetch().
|
inlinenodiscard |
| Property<bool>& aria::async::AsyncResource< T, Key >::is_loading |
| Property<std::optional<::aria::Error> >& aria::async::AsyncResource< T, Key >::error |
| Property<std::string>& aria::async::AsyncResource< T, Key >::error_message |
| Property<std::optional<T> >& aria::async::AsyncResource< T, Key >::data |
| Property<::aria::Loadable<T> >& aria::async::AsyncResource< T, Key >::loadable |
Five-state loadable view-model – Idle / Loading / Refreshing / Success / Error.
Always consistent with the four primitive Properties above. UI code typically prefers this surface (one bind, one switch) over the four-handle surface.