Add synchronous CultMesh document reads

This commit is contained in:
Meta Vens 2026-06-27 16:03:10 +01:00
commit b6d4ebc920
2 changed files with 16 additions and 0 deletions

View file

@ -961,6 +961,12 @@ namespace GameCult.Mesh
return _feed.SnapshotAsync(CultMeshDocumentQueryParameters.Empty);
}
/// <summary>Reads the latest document snapshot synchronously for host APIs that cannot be async.</summary>
public TDocument Latest()
{
return LatestAsync().ConfigureAwait(false).GetAwaiter().GetResult();
}
/// <summary>Watches coherent document snapshots.</summary>
public Observable<TDocument> Watch()
{
@ -1140,6 +1146,13 @@ namespace GameCult.Mesh
return Document<TDocument>().LatestAsync();
}
/// <summary>Reads one typed document synchronously by CLR type or same-schema alias.</summary>
public TDocument Latest<TDocument>()
where TDocument : class
{
return Document<TDocument>().Latest();
}
/// <summary>Watches one typed document by CLR type or same-schema alias.</summary>
public Observable<TDocument> Watch<TDocument>()
where TDocument : class

View file

@ -655,9 +655,11 @@ public sealed class CultMeshStreamingTests
var snapshot = await handle.LatestAsync();
snapshot.Text.Should().Be("primary");
handle.Latest().Text.Should().Be("primary");
var alias = handle.AsSchemaAlias<MeshNoteAliasDocument>();
var aliasSnapshot = await alias.LatestAsync();
alias.Latest().Text.Should().Be("primary");
alias.DocumentId.Should().Be(handle.DocumentId);
alias.SchemaName.Should().Be(handle.SchemaName);
alias.SchemaVersion.Should().Be(handle.SchemaVersion);
@ -729,6 +731,7 @@ public sealed class CultMeshStreamingTests
var aliasSnapshot = await catalog.LatestAsync<MeshNoteAliasDocument>();
aliasSnapshot.Text.Should().Be("catalog-primary");
aliasSnapshot.Revision.Should().Be(3);
catalog.Latest<MeshNoteAliasDocument>().Text.Should().Be("catalog-primary");
}
[Test]