Skip to content

Commit

Permalink
fix: Fix an exception being thrown when a non-existent callback is in…
Browse files Browse the repository at this point in the history
…voked.
  • Loading branch information
s2quake committed Jun 15, 2024
1 parent 8ca2ee0 commit fc44935
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/JSSoft.Communication/Grpc/AdaptorClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,31 @@ private void InvokeCallback(IService service, string name, string[] data)
throw new InvalidOperationException("Invalid method name.");
}

var methodDescriptor = methodDescriptors[name];
var args = _serializer!.DeserializeMany(methodDescriptor.ParameterTypes, data);
var instance = _descriptor!.ClientInstances[service];
Task.Run(() => methodDescriptor.InvokeAsync(_serviceContext, instance, args));
if (methodDescriptors.Contains(name) == true)
{
var methodDescriptor = methodDescriptors[name];
var args = _serializer!.DeserializeMany(methodDescriptor.ParameterTypes, data);
var instance = _descriptor!.ClientInstances[service];
Task.Run(() => methodDescriptor.InvokeAsync(_serviceContext, instance, args));
}
else
{
LogUtility.Warn($"Method '{name}' is not found.");
}
}

private void InvokeCallback(PollReply reply)
{
foreach (var item in reply.Items)
{
var service = _serviceByName[item.ServiceName];
InvokeCallback(service, item.Name, [.. item.Data]);
if (_serviceByName.TryGetValue(item.ServiceName, out var service) == true)
{
InvokeCallback(service, item.Name, [.. item.Data]);
}
else
{
LogUtility.Warn($"Service '{item.ServiceName}' is not found.");
}
}

reply.Items.Clear();
Expand Down

0 comments on commit fc44935

Please sign in to comment.