fix(client/dotnet): restore warnings-as-errors floor; license metadata; LazyBrowseNode publication (Client.Dotnet-022..025)
This commit is contained in:
@@ -12,9 +12,14 @@ public sealed class LazyBrowseNode
|
||||
{
|
||||
private readonly GalaxyRepositoryClient _client;
|
||||
private readonly BrowseChildrenOptions _options;
|
||||
private readonly List<LazyBrowseNode> _children = [];
|
||||
private readonly SemaphoreSlim _expandLock = new(1, 1);
|
||||
private bool _isExpanded;
|
||||
|
||||
// Published once, under _expandLock, when expansion completes. Lock-free readers
|
||||
// see either the empty pre-expansion snapshot or the fully-populated post-expansion
|
||||
// snapshot — never a partially-filled list — because the snapshot is built in a local
|
||||
// and handed off via Volatile.Write (release) paired with Volatile.Read (acquire).
|
||||
private IReadOnlyList<LazyBrowseNode> _children = [];
|
||||
private volatile bool _isExpanded;
|
||||
|
||||
internal LazyBrowseNode(
|
||||
GalaxyRepositoryClient client,
|
||||
@@ -35,7 +40,7 @@ public sealed class LazyBrowseNode
|
||||
public bool HasChildrenHint { get; }
|
||||
|
||||
/// <summary>Direct children loaded by <see cref="ExpandAsync"/>; empty until then.</summary>
|
||||
public IReadOnlyList<LazyBrowseNode> Children => _children;
|
||||
public IReadOnlyList<LazyBrowseNode> Children => Volatile.Read(ref _children);
|
||||
|
||||
/// <summary>True after the first <see cref="ExpandAsync"/> call completes.</summary>
|
||||
public bool IsExpanded => _isExpanded;
|
||||
@@ -46,7 +51,13 @@ public sealed class LazyBrowseNode
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Thread-safe: concurrent callers see exactly one fetch; subsequent callers
|
||||
/// (after the first completes) return immediately.
|
||||
/// (after the first completes) return immediately. <see cref="Children"/> and
|
||||
/// <see cref="IsExpanded"/> may be read concurrently with an in-flight
|
||||
/// <see cref="ExpandAsync"/> on another thread; the populated children are
|
||||
/// published as an immutable snapshot under a release barrier, so a reader that
|
||||
/// observes <see cref="IsExpanded"/> as <see langword="true"/> always sees the
|
||||
/// fully-populated <see cref="Children"/>, and a reader never enumerates a
|
||||
/// partially-built list.
|
||||
/// </remarks>
|
||||
/// <param name="cancellationToken">Token to observe for cancellation.</param>
|
||||
public async Task ExpandAsync(CancellationToken cancellationToken = default)
|
||||
@@ -64,6 +75,10 @@ public sealed class LazyBrowseNode
|
||||
return;
|
||||
}
|
||||
|
||||
// Accumulate into a local list, never the published field, so a lock-free
|
||||
// reader can never observe a half-populated collection or enumerate a list
|
||||
// that is being mutated mid-append.
|
||||
List<LazyBrowseNode> children = [];
|
||||
string pageToken = string.Empty;
|
||||
HashSet<string> seenPageTokens = new(StringComparer.Ordinal);
|
||||
do
|
||||
@@ -79,7 +94,7 @@ public sealed class LazyBrowseNode
|
||||
for (int i = 0; i < reply.Children.Count; i++)
|
||||
{
|
||||
bool hint = i < reply.ChildHasChildren.Count && reply.ChildHasChildren[i];
|
||||
_children.Add(new LazyBrowseNode(_client, reply.Children[i], hint, _options));
|
||||
children.Add(new LazyBrowseNode(_client, reply.Children[i], hint, _options));
|
||||
}
|
||||
|
||||
pageToken = reply.NextPageToken;
|
||||
@@ -91,6 +106,10 @@ public sealed class LazyBrowseNode
|
||||
}
|
||||
while (!string.IsNullOrWhiteSpace(pageToken));
|
||||
|
||||
// Publish the completed, immutable snapshot (release) before marking the node
|
||||
// expanded (the volatile write below). A reader that observes IsExpanded == true
|
||||
// is guaranteed to also observe the fully-populated Children.
|
||||
Volatile.Write(ref _children, children);
|
||||
_isExpanded = true;
|
||||
}
|
||||
finally
|
||||
|
||||
@@ -21,10 +21,15 @@
|
||||
<PackageId>ZB.MOM.WW.MxGateway.Client</PackageId>
|
||||
<Description>.NET 10 gRPC client for the MxAccessGateway service. Provides typed wrappers, retry, and a lazy-browse walker over the Galaxy Repository hierarchy.</Description>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<!-- Only the shipped library generates XML docs (matching src/Contracts). The Cli and
|
||||
Tests projects are not packable and do not document their public surface, so this
|
||||
stays out of the shared Directory.Build.props to avoid CS1591 on test classes. -->
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="..\README.md" Pack="true" PackagePath="\" />
|
||||
<None Include="..\LICENSE.txt" Pack="true" PackagePath="\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user