mirror of
https://github.com/dotnet/MQTTnet.git
synced 2026-10-16 09:13:02 +08:00
Fix awaits in try/catch
This commit is contained in:
@@ -14,14 +14,14 @@ namespace MQTTnet.Implementations
|
||||
private int WebSocketBufferSize;
|
||||
private int WebSocketBufferOffset;
|
||||
|
||||
public Task ConnectAsync(MqttClientOptions options)
|
||||
public async Task ConnectAsync(MqttClientOptions options)
|
||||
{
|
||||
_webSocket = null;
|
||||
|
||||
try
|
||||
{
|
||||
_webSocket = new ClientWebSocket();
|
||||
return _webSocket.ConnectAsync(new Uri(options.Server), CancellationToken.None);
|
||||
await _webSocket.ConnectAsync(new Uri(options.Server), CancellationToken.None);
|
||||
}
|
||||
catch (WebSocketException exception)
|
||||
{
|
||||
@@ -75,16 +75,16 @@ namespace MQTTnet.Implementations
|
||||
}
|
||||
}
|
||||
|
||||
public Task WriteAsync(byte[] buffer)
|
||||
public async Task WriteAsync(byte[] buffer)
|
||||
{
|
||||
if (buffer == null) {
|
||||
if (buffer == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(buffer));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return _webSocket.SendAsync(new ArraySegment<byte>(buffer), WebSocketMessageType.Binary, true,
|
||||
CancellationToken.None);
|
||||
await _webSocket.SendAsync(new ArraySegment<byte>(buffer), WebSocketMessageType.Binary, true, CancellationToken.None);
|
||||
}
|
||||
catch (WebSocketException exception)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user