Skip to content
Merged
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
16 changes: 5 additions & 11 deletions dotnet/src/webdriver/BiDi/Broker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal sealed class Broker : IAsyncDisposable
private readonly ITransport _transport;

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

cts.Token.Register(() => tcs.TrySetCanceled(cts.Token));
var commandInfo = new CommandInfo(command.Id, tcs, jsonResultTypeInfo);
var commandInfo = new CommandInfo(tcs, jsonResultTypeInfo);
_pendingCommands[command.Id] = commandInfo;
var data = JsonSerializer.SerializeToUtf8Bytes(command, jsonCommandTypeInfo);

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

eventArgs.BiDi = _bidi;

var messageEvent = (method, eventArgs);
_pendingEvents.Writer.TryWrite(messageEvent);
_pendingEvents.Writer.TryWrite(new EventInfo(method, eventArgs));
}
else
{
Expand All @@ -321,12 +320,7 @@ private void ProcessReceivedMessage(byte[]? data)
}
}

class CommandInfo(long id, TaskCompletionSource<EmptyResult> taskCompletionSource, JsonTypeInfo jsonResultTypeInfo)
{
public long Id { get; } = id;

public TaskCompletionSource<EmptyResult> TaskCompletionSource { get; } = taskCompletionSource;
private readonly record struct CommandInfo(TaskCompletionSource<EmptyResult> TaskCompletionSource, JsonTypeInfo JsonResultTypeInfo);

public JsonTypeInfo JsonResultTypeInfo { get; } = jsonResultTypeInfo;
};
private readonly record struct EventInfo(string Method, EventArgs Params);
}