Skip to content

Commit

Permalink
Update the OpenNettyConnection static APIs to make the cancellation t…
Browse files Browse the repository at this point in the history
…oken mandatory
  • Loading branch information
kevinchalet committed Dec 10, 2024
1 parent a3819dd commit 376eb8a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,11 @@ await Task.Delay(-1);
> parity : Parity.None,
> dataBits: 8,
> stopBits: StopBits.One);
>
> using var source = new CancellationTokenSource();
> source.CancelAfter(TimeSpan.FromSeconds(10));
>
> await using var connection = await OpenNettyConnection.CreateSerialConnectionAsync(port);
> await using var connection = await OpenNettyConnection.CreateSerialConnectionAsync(port, source.Token);
>
> var message = OpenNettyMessage.CreateCommand(
> protocol: OpenNettyProtocol.Zigbee,
Expand All @@ -161,9 +164,9 @@ await Task.Delay(-1);
> media : OpenNettyMedia.Radio,
> mode : OpenNettyMode.Unicast);
>
> await connection.SendAsync(message.Frame, CancellationToken.None);
> await connection.SendAsync(message.Frame, source.Token);
>
> if (await connection.ReceiveAsync(CancellationToken.None) != OpenNettyFrames.Acknowledgement)
> if (await connection.ReceiveAsync(source.Token) != OpenNettyFrames.Acknowledgement)
> {
> throw new ApplicationException("The frame was not acknowledged by the gateway.");
> }
Expand Down
6 changes: 3 additions & 3 deletions src/OpenNetty/OpenNettyConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public abstract class OpenNettyConnection : IAsyncDisposable
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous
/// operation and whose result returns the created connection.
/// </returns>
public static ValueTask<OpenNettyConnection> CreateAsync(OpenNettyGateway gateway, CancellationToken cancellationToken = default)
public static ValueTask<OpenNettyConnection> CreateAsync(OpenNettyGateway gateway, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(gateway);

Expand All @@ -87,7 +87,7 @@ public static ValueTask<OpenNettyConnection> CreateAsync(OpenNettyGateway gatewa
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous
/// operation and whose result returns the created serial connection.
/// </returns>
public static async ValueTask<OpenNettyConnection> CreateSerialConnectionAsync(SerialPort port, CancellationToken cancellationToken = default)
public static async ValueTask<OpenNettyConnection> CreateSerialConnectionAsync(SerialPort port, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(port);

Expand All @@ -110,7 +110,7 @@ public static async ValueTask<OpenNettyConnection> CreateSerialConnectionAsync(S
/// A <see cref="ValueTask"/> that can be used to monitor the asynchronous
/// operation and whose result returns the created TCP connection.
/// </returns>
public static async ValueTask<OpenNettyConnection> CreateTcpConnectionAsync(IPEndPoint endpoint, CancellationToken cancellationToken = default)
public static async ValueTask<OpenNettyConnection> CreateTcpConnectionAsync(IPEndPoint endpoint, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(endpoint);

Expand Down

0 comments on commit 376eb8a

Please sign in to comment.