WriteAsync must be awaited (#4491)

This commit is contained in:
Ryan Sweet
2024-12-03 09:10:46 -08:00
committed by GitHub
parent 1c09de8d47
commit 79c5aaa1a4
3 changed files with 7 additions and 10 deletions

View File

@@ -137,7 +137,7 @@ public sealed class GrpcGateway : BackgroundService, IGateway
}
_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()
{

View File

@@ -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<Dictionary<string, List<string>>> GetSubscriptions(string agentType);
}

View File

@@ -15,7 +15,7 @@ internal sealed class SubscriptionsGrain([PersistentState("state", "PubSubStore"
}
return new ValueTask<Dictionary<string, List<string>>>(_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 @@ internal sealed class SubscriptionsGrain([PersistentState("state", "PubSubStore"
}
_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 @@ internal sealed class SubscriptionsGrain([PersistentState("state", "PubSubStore"
}
_subscriptions[topic] = subscriptions;
state.State.Subscriptions = _subscriptions;
state.WriteStateAsync();
return ValueTask.CompletedTask;
await state.WriteStateAsync();
}
}
public sealed class SubscriptionsState