Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WriteAsync must be awaited in Grains #4491

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public ValueTask<Dictionary<string, List<string>>> GetSubscriptions(string? agen
}
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))
{
Expand All @@ -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))
{
Expand All @@ -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
Expand Down
Loading