Skip to content

Commit

Permalink
Update JsonRpcConnection.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
LPeter1997 committed Sep 30, 2023
1 parent 8819033 commit 19c4e84
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Draco.JsonRpc/JsonRpcConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,22 @@ public abstract class JsonRpcConnection<TMessage>

private readonly CancellationTokenSource shutdownTokenSource = new();

private readonly Dictionary<string, JsonRpcMethodHandler> methodHandlers = new();

private int lastMessageId = 0;
private readonly ConcurrentDictionary<object, CancellationTokenSource> pendingIncomingRequests = new();

/// <summary>
/// Registers an RPC handler method.
/// </summary>
/// <param name="handlerMethod">The handler method info.</param>
/// <param name="target">The method invocation target.</param>
public void AddRpcMethod(MethodInfo handlerMethod, object? target)
{
var handler = new JsonRpcMethodHandler(handlerMethod, target);
this.methodHandlers.Add(handler.MethodName, handler);
}

private int NextMessageId() => Interlocked.Increment(ref this.lastMessageId);

private async Task<TMessage?> ReadMessage()
Expand Down

0 comments on commit 19c4e84

Please sign in to comment.