Skip to content

Commit abc4eaa

Browse files
authored
[dotnet] [bidi] Refactor CommandInfo and EventInfo to structs (#17080)
1 parent 7d7ceae commit abc4eaa

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

dotnet/src/webdriver/BiDi/Broker.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal sealed class Broker : IAsyncDisposable
3737
private readonly ITransport _transport;
3838

3939
private readonly ConcurrentDictionary<long, CommandInfo> _pendingCommands = new();
40-
private readonly Channel<(string Method, EventArgs Params)> _pendingEvents = Channel.CreateUnbounded<(string Method, EventArgs Params)>(new()
40+
private readonly Channel<EventInfo> _pendingEvents = Channel.CreateUnbounded<EventInfo>(new()
4141
{
4242
SingleReader = true,
4343
SingleWriter = true
@@ -152,7 +152,7 @@ public async Task<TResult> ExecuteCommandAsync<TCommand, TResult>(TCommand comma
152152
cts.CancelAfter(timeout);
153153

154154
cts.Token.Register(() => tcs.TrySetCanceled(cts.Token));
155-
var commandInfo = new CommandInfo(command.Id, tcs, jsonResultTypeInfo);
155+
var commandInfo = new CommandInfo(tcs, jsonResultTypeInfo);
156156
_pendingCommands[command.Id] = commandInfo;
157157
var data = JsonSerializer.SerializeToUtf8Bytes(command, jsonCommandTypeInfo);
158158

@@ -294,8 +294,7 @@ private void ProcessReceivedMessage(byte[]? data)
294294

295295
eventArgs.BiDi = _bidi;
296296

297-
var messageEvent = (method, eventArgs);
298-
_pendingEvents.Writer.TryWrite(messageEvent);
297+
_pendingEvents.Writer.TryWrite(new EventInfo(method, eventArgs));
299298
}
300299
else
301300
{
@@ -321,12 +320,7 @@ private void ProcessReceivedMessage(byte[]? data)
321320
}
322321
}
323322

324-
class CommandInfo(long id, TaskCompletionSource<EmptyResult> taskCompletionSource, JsonTypeInfo jsonResultTypeInfo)
325-
{
326-
public long Id { get; } = id;
327-
328-
public TaskCompletionSource<EmptyResult> TaskCompletionSource { get; } = taskCompletionSource;
323+
private readonly record struct CommandInfo(TaskCompletionSource<EmptyResult> TaskCompletionSource, JsonTypeInfo JsonResultTypeInfo);
329324

330-
public JsonTypeInfo JsonResultTypeInfo { get; } = jsonResultTypeInfo;
331-
};
325+
private readonly record struct EventInfo(string Method, EventArgs Params);
332326
}

0 commit comments

Comments
 (0)