From 79c5aaa1a4c6251cc6b920094dc0bb00cf357942 Mon Sep 17 00:00:00 2001 From: Ryan Sweet Date: Tue, 3 Dec 2024 09:10:46 -0800 Subject: [PATCH] WriteAsync must be awaited (#4491) --- .../Agents/Services/Grpc/GrpcGateway.cs | 2 +- .../Agents/Services/Orleans/ISubscriptionsGrain.cs | 4 ++-- .../Agents/Services/Orleans/SubscriptionsGrain.cs | 11 ++++------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/dotnet/src/Microsoft.AutoGen/Agents/Services/Grpc/GrpcGateway.cs b/dotnet/src/Microsoft.AutoGen/Agents/Services/Grpc/GrpcGateway.cs index ea488568e4e6..9ba36410a30f 100644 --- a/dotnet/src/Microsoft.AutoGen/Agents/Services/Grpc/GrpcGateway.cs +++ b/dotnet/src/Microsoft.AutoGen/Agents/Services/Grpc/GrpcGateway.cs @@ -137,7 +137,7 @@ private async ValueTask AddSubscriptionAsync(GrpcWorkerConnection connection, Ad } _subscriptionsByAgentType[agentType] = request.Subscription; _subscriptionsByTopic.GetOrAdd(topic, _ => []).Add(agentType); - await _subscriptions.Subscribe(topic, agentType); + await _subscriptions.SubscribeAsync(topic, agentType); //var response = new AddSubscriptionResponse { RequestId = request.RequestId, Error = "", Success = true }; Message response = new() { diff --git a/dotnet/src/Microsoft.AutoGen/Agents/Services/Orleans/ISubscriptionsGrain.cs b/dotnet/src/Microsoft.AutoGen/Agents/Services/Orleans/ISubscriptionsGrain.cs index 302df9ebff98..d3af459bb7ff 100644 --- a/dotnet/src/Microsoft.AutoGen/Agents/Services/Orleans/ISubscriptionsGrain.cs +++ b/dotnet/src/Microsoft.AutoGen/Agents/Services/Orleans/ISubscriptionsGrain.cs @@ -4,7 +4,7 @@ namespace Microsoft.AutoGen.Agents; public interface ISubscriptionsGrain : IGrainWithIntegerKey { - ValueTask Subscribe(string agentType, string topic); - ValueTask Unsubscribe(string agentType, string topic); + ValueTask SubscribeAsync(string agentType, string topic); + ValueTask UnsubscribeAsync(string agentType, string topic); ValueTask>> GetSubscriptions(string agentType); } diff --git a/dotnet/src/Microsoft.AutoGen/Agents/Services/Orleans/SubscriptionsGrain.cs b/dotnet/src/Microsoft.AutoGen/Agents/Services/Orleans/SubscriptionsGrain.cs index 682073f0b97c..0e647dbab980 100644 --- a/dotnet/src/Microsoft.AutoGen/Agents/Services/Orleans/SubscriptionsGrain.cs +++ b/dotnet/src/Microsoft.AutoGen/Agents/Services/Orleans/SubscriptionsGrain.cs @@ -15,7 +15,7 @@ public ValueTask>> GetSubscriptions(string? agen } return new ValueTask>>(_subscriptions); } - public ValueTask Subscribe(string agentType, string topic) + public async ValueTask SubscribeAsync(string agentType, string topic) { if (!_subscriptions.TryGetValue(topic, out var subscriptions)) { @@ -27,11 +27,9 @@ public ValueTask Subscribe(string agentType, string topic) } _subscriptions[topic] = subscriptions; state.State.Subscriptions = _subscriptions; - state.WriteStateAsync(); - - return ValueTask.CompletedTask; + await state.WriteStateAsync().ConfigureAwait(false); } - public ValueTask Unsubscribe(string agentType, string topic) + public async ValueTask UnsubscribeAsync(string agentType, string topic) { if (!_subscriptions.TryGetValue(topic, out var subscriptions)) { @@ -43,8 +41,7 @@ public ValueTask Unsubscribe(string agentType, string topic) } _subscriptions[topic] = subscriptions; state.State.Subscriptions = _subscriptions; - state.WriteStateAsync(); - return ValueTask.CompletedTask; + await state.WriteStateAsync(); } } public sealed class SubscriptionsState