Skip to content

Commit 661c334

Browse files
committed
Non nullable
1 parent 277f0d7 commit 661c334

File tree

3 files changed

+24
-22
lines changed

3 files changed

+24
-22
lines changed

dotnet/src/webdriver/BiDi/Broker.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ private async Task ProcessEventsAwaiterAsync()
127127
}
128128
}
129129

130-
public async Task<TResult> ExecuteCommandAsync<TCommand, TResult>(TCommand command, CommandOptions? options, JsonTypeInfo<TCommand> jsonCommandTypeInfo, JsonTypeInfo<TResult> jsonResultTypeInfo, CancellationToken? cancellationToken)
130+
public async Task<TResult> ExecuteCommandAsync<TCommand, TResult>(TCommand command, CommandOptions? options, JsonTypeInfo<TCommand> jsonCommandTypeInfo, JsonTypeInfo<TResult> jsonResultTypeInfo, CancellationToken cancellationToken)
131131
where TCommand : Command
132132
where TResult : EmptyResult
133133
{
@@ -137,10 +137,12 @@ public async Task<TResult> ExecuteCommandAsync<TCommand, TResult>(TCommand comma
137137

138138
var timeout = options?.Timeout ?? TimeSpan.FromSeconds(30);
139139

140-
using var cts = cancellationToken.HasValue ?
141-
CancellationTokenSource.CreateLinkedTokenSource(cancellationToken.Value) :
142-
new CancellationTokenSource(timeout);
140+
using var timeoutCts = new CancellationTokenSource(timeout);
141+
using var linkedCts = cancellationToken != default ?
142+
CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutCts.Token) :
143+
null;
143144

145+
var cts = linkedCts ?? timeoutCts;
144146
cts.Token.Register(() => tcs.TrySetCanceled(cts.Token));
145147
var commandInfo = new CommandInfo(command.Id, tcs, jsonResultTypeInfo);
146148
_pendingCommands[command.Id] = commandInfo;

dotnet/src/webdriver/BiDi/Browser/BrowserModule.cs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
using OpenQA.Selenium.BiDi.Json.Converters;
2121
using System.Text.Json;
2222
using System.Text.Json.Serialization;
23+
using System.Threading;
2324
using System.Threading.Tasks;
2425

2526
namespace OpenQA.Selenium.BiDi.Browser;
@@ -28,55 +29,54 @@ public sealed class BrowserModule : Module
2829
{
2930
private BrowserJsonSerializerContext _jsonContext = null!;
3031

31-
public async Task<CloseResult> CloseAsync(CloseOptions? options = null)
32+
public async Task<CloseResult> CloseAsync(CloseOptions? options = null, CancellationToken cancellationToken = default)
3233
{
33-
return await ExecuteCommandAsync(new CloseCommand(), options, _jsonContext.CloseCommand, _jsonContext.CloseResult).ConfigureAwait(false);
34+
return await ExecuteCommandAsync(new CloseCommand(), options, _jsonContext.CloseCommand, _jsonContext.CloseResult, cancellationToken).ConfigureAwait(false);
3435
}
3536

36-
public async Task<CreateUserContextResult> CreateUserContextAsync(CreateUserContextOptions? options = null)
37+
public async Task<CreateUserContextResult> CreateUserContextAsync(CreateUserContextOptions? options = null, CancellationToken cancellationToken = default)
3738
{
3839
var @params = new CreateUserContextParameters(options?.AcceptInsecureCerts, options?.Proxy, options?.UnhandledPromptBehavior);
3940

40-
return await ExecuteCommandAsync(new CreateUserContextCommand(@params), options, _jsonContext.CreateUserContextCommand, _jsonContext.CreateUserContextResult).ConfigureAwait(false);
41+
return await ExecuteCommandAsync(new CreateUserContextCommand(@params), options, _jsonContext.CreateUserContextCommand, _jsonContext.CreateUserContextResult, cancellationToken).ConfigureAwait(false);
4142
}
4243

43-
public async Task<GetUserContextsResult> GetUserContextsAsync(GetUserContextsOptions? options = null)
44+
public async Task<GetUserContextsResult> GetUserContextsAsync(GetUserContextsOptions? options = null, CancellationToken cancellationToken = default)
4445
{
45-
return await ExecuteCommandAsync(new GetUserContextsCommand(), options, _jsonContext.GetUserContextsCommand, _jsonContext.GetUserContextsResult).ConfigureAwait(false);
46+
return await ExecuteCommandAsync(new GetUserContextsCommand(), options, _jsonContext.GetUserContextsCommand, _jsonContext.GetUserContextsResult, cancellationToken).ConfigureAwait(false);
4647
}
4748

48-
public async Task<RemoveUserContextResult> RemoveUserContextAsync(UserContext userContext, RemoveUserContextOptions? options = null)
49+
public async Task<RemoveUserContextResult> RemoveUserContextAsync(UserContext userContext, RemoveUserContextOptions? options = null, CancellationToken cancellationToken = default)
4950
{
5051
var @params = new RemoveUserContextParameters(userContext);
5152

52-
return await ExecuteCommandAsync(new RemoveUserContextCommand(@params), options, _jsonContext.RemoveUserContextCommand, _jsonContext.RemoveUserContextResult).ConfigureAwait(false);
53+
return await ExecuteCommandAsync(new RemoveUserContextCommand(@params), options, _jsonContext.RemoveUserContextCommand, _jsonContext.RemoveUserContextResult, cancellationToken).ConfigureAwait(false);
5354
}
5455

55-
public async Task<GetClientWindowsResult> GetClientWindowsAsync(GetClientWindowsOptions? options = null)
56+
public async Task<GetClientWindowsResult> GetClientWindowsAsync(GetClientWindowsOptions? options = null, CancellationToken cancellationToken = default)
5657
{
57-
return await ExecuteCommandAsync(new(), options, _jsonContext.GetClientWindowsCommand, _jsonContext.GetClientWindowsResult
58-
).ConfigureAwait(false);
58+
return await ExecuteCommandAsync(new(), options, _jsonContext.GetClientWindowsCommand, _jsonContext.GetClientWindowsResult, cancellationToken).ConfigureAwait(false);
5959
}
6060

61-
public async Task<SetDownloadBehaviorResult> SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null)
61+
public async Task<SetDownloadBehaviorResult> SetDownloadBehaviorAllowedAsync(string destinationFolder, SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default)
6262
{
6363
var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorAllowed(destinationFolder), options?.UserContexts);
6464

65-
return await ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, _jsonContext.SetDownloadBehaviorCommand, _jsonContext.SetDownloadBehaviorResult).ConfigureAwait(false);
65+
return await ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, _jsonContext.SetDownloadBehaviorCommand, _jsonContext.SetDownloadBehaviorResult, cancellationToken).ConfigureAwait(false);
6666
}
6767

68-
public async Task<SetDownloadBehaviorResult> SetDownloadBehaviorAllowedAsync(SetDownloadBehaviorOptions? options = null)
68+
public async Task<SetDownloadBehaviorResult> SetDownloadBehaviorAllowedAsync(SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default)
6969
{
7070
var @params = new SetDownloadBehaviorParameters(null, options?.UserContexts);
7171

72-
return await ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, _jsonContext.SetDownloadBehaviorCommand, _jsonContext.SetDownloadBehaviorResult).ConfigureAwait(false);
72+
return await ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, _jsonContext.SetDownloadBehaviorCommand, _jsonContext.SetDownloadBehaviorResult, cancellationToken).ConfigureAwait(false);
7373
}
7474

75-
public async Task<SetDownloadBehaviorResult> SetDownloadBehaviorDeniedAsync(SetDownloadBehaviorOptions? options = null)
75+
public async Task<SetDownloadBehaviorResult> SetDownloadBehaviorDeniedAsync(SetDownloadBehaviorOptions? options = null, CancellationToken cancellationToken = default)
7676
{
7777
var @params = new SetDownloadBehaviorParameters(new DownloadBehaviorDenied(), options?.UserContexts);
7878

79-
return await ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, _jsonContext.SetDownloadBehaviorCommand, _jsonContext.SetDownloadBehaviorResult).ConfigureAwait(false);
79+
return await ExecuteCommandAsync(new SetDownloadBehaviorCommand(@params), options, _jsonContext.SetDownloadBehaviorCommand, _jsonContext.SetDownloadBehaviorResult, cancellationToken).ConfigureAwait(false);
8080
}
8181

8282
protected override void Initialize(BiDi bidi, JsonSerializerOptions jsonSerializerOptions)

dotnet/src/webdriver/BiDi/Module.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public abstract class Module
2929
{
3030
private Broker Broker { get; set; } = null!;
3131

32-
protected Task<TResult> ExecuteCommandAsync<TCommand, TResult>(TCommand command, CommandOptions? options, JsonTypeInfo<TCommand> jsonCommandTypeInfo, JsonTypeInfo<TResult> jsonResultTypeInfo, CancellationToken? cancellationToken)
32+
protected Task<TResult> ExecuteCommandAsync<TCommand, TResult>(TCommand command, CommandOptions? options, JsonTypeInfo<TCommand> jsonCommandTypeInfo, JsonTypeInfo<TResult> jsonResultTypeInfo, CancellationToken cancellationToken)
3333
where TCommand : Command
3434
where TResult : EmptyResult
3535
{

0 commit comments

Comments
 (0)