Skip to content

Commit

Permalink
improved passing CancellationToken = default
Browse files Browse the repository at this point in the history
  • Loading branch information
AntyaDev committed Jan 12, 2024
1 parent 4d99211 commit 3b406b8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/NBomber.WebSockets/WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class WebSocket(WebSocketConfig config) : IDisposable
/// <param name="cancellationToken">A <see cref="CancellationToken"/> used to propagate notification that the operation should be canceled.</param>
/// <exception cref="WebSocketException">Thrown when an error occurs during WebSocket communication.</exception>
/// <exception cref="OperationCanceledException">Thrown if the receive operation is canceled by the provided cancellation token.</exception>
public async ValueTask<WebSocketResponse> Receive(CancellationToken? cancellationToken = null)
public async ValueTask<WebSocketResponse> Receive(CancellationToken cancellationToken = default)
{
var endOfMessage = false;
var ms = MsStreamManager.GetStream();
Expand All @@ -36,7 +36,7 @@ public async ValueTask<WebSocketResponse> Receive(CancellationToken? cancellatio
while (!endOfMessage)
{
var buffer = ms.GetMemory(config.DefaultBufferSize);
var message = await Client.ReceiveAsync(buffer, cancellationToken ?? CancellationToken.None).ConfigureAwait(false);
var message = await Client.ReceiveAsync(buffer, cancellationToken).ConfigureAwait(false);

if (message.MessageType == WebSocketMessageType.Close)
{
Expand Down
20 changes: 10 additions & 10 deletions src/NBomber.WebSockets/WebSocketExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public static class WebSocketExtensions
/// <param name="cancellationToken">A <see cref="CancellationToken"/> used to propagate notification that the operation should be canceled.</param>
/// <exception cref="WebSocketException">Thrown when an error occurs during WebSocket communication.</exception>
/// <exception cref="OperationCanceledException">Thrown if the receive operation is canceled by the provided cancellation token.</exception>
public static Task Connect(this WebSocket webSocket, string url, CancellationToken? cancellationToken = null)
public static Task Connect(this WebSocket webSocket, string url, CancellationToken cancellationToken = default)
{
return webSocket.Client.ConnectAsync(new Uri(url), cancellationToken ?? CancellationToken.None);
return webSocket.Client.ConnectAsync(new Uri(url), cancellationToken);
}

/// <summary>
Expand All @@ -27,9 +27,9 @@ public static Task Connect(this WebSocket webSocket, string url, CancellationTok
/// <param name="cancellationToken">A <see cref="CancellationToken"/> used to propagate notification that the operation should be canceled.</param>
/// <exception cref="WebSocketException">Thrown when an error occurs during WebSocket communication.</exception>
/// <exception cref="OperationCanceledException">Thrown if the receive operation is canceled by the provided cancellation token.</exception>
public static Task Connect(this WebSocket webSocket, Uri uri, CancellationToken? cancellationToken = null)
public static Task Connect(this WebSocket webSocket, Uri uri, CancellationToken cancellationToken = default)
{
return webSocket.Client.ConnectAsync(uri, cancellationToken ?? CancellationToken.None);
return webSocket.Client.ConnectAsync(uri, cancellationToken);
}

/// <summary>
Expand All @@ -39,9 +39,9 @@ public static Task Connect(this WebSocket webSocket, Uri uri, CancellationToken?
/// <param name="cancellationToken">A <see cref="CancellationToken"/> used to propagate notification that the operation should be canceled.</param>
/// <exception cref="WebSocketException">Thrown when an error occurs during WebSocket communication.</exception>
/// <exception cref="OperationCanceledException">Thrown if the receive operation is canceled by the provided cancellation token.</exception>
public static Task Close(this WebSocket webSocket, WebSocketCloseStatus? closeStatus = null, CancellationToken? cancellationToken = null)
public static Task Close(this WebSocket webSocket, WebSocketCloseStatus? closeStatus = null, CancellationToken cancellationToken = default)
{
return webSocket.Client.CloseAsync(closeStatus ?? WebSocketCloseStatus.NormalClosure, null, cancellationToken ?? CancellationToken.None);
return webSocket.Client.CloseAsync(closeStatus ?? WebSocketCloseStatus.NormalClosure, null, cancellationToken);
}

/// <summary>
Expand All @@ -51,7 +51,7 @@ public static Task Close(this WebSocket webSocket, WebSocketCloseStatus? closeSt
/// <param name="cancellationToken">A <see cref="CancellationToken"/> used to propagate notification that the operation should be canceled.</param>
/// <exception cref="WebSocketException">Thrown when an error occurs during WebSocket communication.</exception>
/// <exception cref="OperationCanceledException">Thrown if the receive operation is canceled by the provided cancellation token.</exception>
public static ValueTask Send(this WebSocket webSocket, string text, CancellationToken? cancellationToken = null)
public static ValueTask Send(this WebSocket webSocket, string text, CancellationToken cancellationToken = default)
{
using var ms = MsStreamManager.GetStream();

Expand All @@ -61,7 +61,7 @@ public static ValueTask Send(this WebSocket webSocket, string text, Cancellation

var msg = ms.GetBuffer().AsMemory(0, (int) ms.Length);

return webSocket.Client.SendAsync(msg, WebSocketMessageType.Text, true, cancellationToken ?? CancellationToken.None);
return webSocket.Client.SendAsync(msg, WebSocketMessageType.Text, true, cancellationToken);
}

/// <summary>
Expand All @@ -71,8 +71,8 @@ public static ValueTask Send(this WebSocket webSocket, string text, Cancellation
/// <param name="cancellationToken">A <see cref="CancellationToken"/> used to propagate notification that the operation should be canceled.</param>
/// <exception cref="WebSocketException">Thrown when an error occurs during WebSocket communication.</exception>
/// <exception cref="OperationCanceledException">Thrown if the receive operation is canceled by the provided cancellation token.</exception>
public static ValueTask Send(this WebSocket webSocket, ReadOnlyMemory<byte> payload, CancellationToken? cancellationToken = null)
public static ValueTask Send(this WebSocket webSocket, ReadOnlyMemory<byte> payload, CancellationToken cancellationToken = default)
{
return webSocket.Client.SendAsync(payload, WebSocketMessageType.Binary, true, cancellationToken ?? CancellationToken.None);
return webSocket.Client.SendAsync(payload, WebSocketMessageType.Binary, true, cancellationToken);
}
}

0 comments on commit 3b406b8

Please sign in to comment.