Fix awaits in try/catch

This commit is contained in:
Christian Kratky
2017-09-12 21:50:07 +02:00
parent f7a8b764d0
commit 16bc9cb203
8 changed files with 40 additions and 38 deletions
@@ -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)
{