ArlecchinoAsyncStore class
Namespace: Arlecchino.Atoms · Assembly: Arlecchino
A store that has to fetch something before it holds the truth. Override ArlecchinoAsyncStore.LoadAsync, and the load is started as the application starts and its bookkeeping kept.
public sealed class SettingsStore : ArlecchinoAsyncStore
{
public TrackedAtom<string> Server { get; } = new("127.0.0.1");
protected override async Task LoadAsync(CancellationToken token)
{
await using var fs = new FileStream(SettingsPath, FileMode.Open, FileAccess.Read);
var saved = await JsonSerializer.DeserializeAsync<Saved>(fs, cancellationToken: token);
Server.Post(saved.Server);
}
}
public abstract class ArlecchinoAsyncStore : IArlecchinoStore
Implements IArlecchinoStore
Constructors
| Member | Summary |
|---|---|
ArlecchinoAsyncStore() | Creates the store. |
Properties
| Member | Summary |
|---|---|
Error | What the load threw, or null while it has not failed. |
Failed | Whether the load threw. What it threw is in ArlecchinoAsyncStore.Error. |
IsLoaded | Whether the load finished and the atoms hold what it fetched. |
IsLoading | Whether the load is still running. |
Ready | Completes when the store is loaded, faults with whatever ArlecchinoAsyncStore.LoadAsync threw, and cancels when the application stopped first. A view reads ArlecchinoAsyncStore.Status instead of awaiting it. |
Status | How the load is going, as an atom, so a view that reads it redraws when it changes. |
Methods
| Member | Summary |
|---|---|
LoadAsync(CancellationToken) | Fetches what the store needs, off the drawing thread, so what it loads reaches the atoms through Post. Throwing is a normal outcome and turns the status to failed. |
Constructors in detail
ArlecchinoAsyncStore()
public ArlecchinoAsyncStore();
Creates the store.
Properties in detail
Error
public IReadableAtom<Exception?> Error { get; }
What the load threw, or null while it has not failed.
Type IReadableAtom<Exception>
Failed
public bool Failed { get; }
Whether the load threw. What it threw is in ArlecchinoAsyncStore.Error.
Type bool
IsLoaded
public bool IsLoaded { get; }
Whether the load finished and the atoms hold what it fetched.
Type bool
IsLoading
public bool IsLoading { get; }
Whether the load is still running.
Type bool
Ready
public Task Ready { get; }
Completes when the store is loaded, faults with whatever ArlecchinoAsyncStore.LoadAsync threw, and cancels when the application stopped first. A view reads ArlecchinoAsyncStore.Status instead of awaiting it.
Type Task
Status
public IReadableAtom<LoadStatus> Status { get; }
How the load is going, as an atom, so a view that reads it redraws when it changes.
Type IReadableAtom<LoadStatus>
Methods in detail
LoadAsync(CancellationToken)
public abstract Task LoadAsync(CancellationToken token);
Fetches what the store needs, off the drawing thread, so what it loads reaches the atoms through Post. Throwing is a normal outcome and turns the status to failed.
Parameters
| Name | Type | Description |
|---|---|---|
token | CancellationToken | Canceled when the application is shutting down. |
Returns Task — A task that completes when the store is ready.