Skip to content

Commit

Permalink
ConfigureAwait(false)
Browse files Browse the repository at this point in the history
  • Loading branch information
xljiulang committed Dec 4, 2024
1 parent 54f0b4d commit ee4de82
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void OnApplicationStarted()

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
await _applicationStartedTask.WaitAsync(stoppingToken);
await _aspNetCoreMqttServer.StartAsync(stoppingToken);
await _applicationStartedTask.WaitAsync(stoppingToken).ConfigureAwait(false);
await _aspNetCoreMqttServer.StartAsync(stoppingToken).ConfigureAwait(false) ;
}

public override Task StopAsync(CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static async Task<ClientConnectionContext> CreateAsync(MqttClientTcpOptio
}
catch (Exception)
{
await sslStream.DisposeAsync();
await sslStream.DisposeAsync().ConfigureAwait(false);
throw;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public ClientConnectionContext(Stream stream)

public override async ValueTask DisposeAsync()
{
await _stream.DisposeAsync();
await _stream.DisposeAsync().ConfigureAwait(false);
_connectionCloseSource.Cancel();
_connectionCloseSource.Dispose();
}
Expand Down
4 changes: 2 additions & 2 deletions Source/MQTTnet.AspnetCore/Internal/MqttChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ private static bool IsTlsConnection(IHttpContextFeature? _httpContextFeature, IT

public async Task DisconnectAsync()
{
await _input.CompleteAsync();
await _output.CompleteAsync();
await _input.CompleteAsync().ConfigureAwait(false);
await _output.CompleteAsync().ConfigureAwait(false);
}

public virtual void Dispose()
Expand Down
14 changes: 7 additions & 7 deletions Source/MQTTnet.AspnetCore/Internal/MqttClientChannelAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ public async Task ConnectAsync(CancellationToken cancellationToken)
{
_connection = _channelOptions switch
{
MqttClientTcpOptions tcpOptions => await ClientConnectionContext.CreateAsync(tcpOptions, cancellationToken),
MqttClientWebSocketOptions webSocketOptions => await ClientConnectionContext.CreateAsync(webSocketOptions, cancellationToken),
MqttClientTcpOptions tcpOptions => await ClientConnectionContext.CreateAsync(tcpOptions, cancellationToken).ConfigureAwait(false),
MqttClientWebSocketOptions webSocketOptions => await ClientConnectionContext.CreateAsync(webSocketOptions, cancellationToken).ConfigureAwait(false),
_ => throw new NotSupportedException(),
};
_channel = new MqttChannel(_packetFormatterAdapter, _connection, _packetInspector);
}

public async Task DisconnectAsync(CancellationToken cancellationToken)
public Task DisconnectAsync(CancellationToken cancellationToken)
{
await GetChannel().DisconnectAsync();
return GetChannel().DisconnectAsync();
}

public async ValueTask DisposeAsync()
Expand All @@ -74,19 +74,19 @@ public async ValueTask DisposeAsync()

if (_channel != null)
{
await _channel.DisconnectAsync();
await _channel.DisconnectAsync().ConfigureAwait(false);
_channel.Dispose();
}

if (_connection != null)
{
await _connection.DisposeAsync();
await _connection.DisposeAsync().ConfigureAwait(false);
}
}

public void Dispose()
{
DisposeAsync().GetAwaiter().GetResult();
DisposeAsync().ConfigureAwait(false).GetAwaiter().GetResult();
}

public Task<MqttPacket?> ReceivePacketAsync(CancellationToken cancellationToken)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public async Task InvokeAsync(ConnectionDelegate next, ConnectionContext connect

if (protocols == MqttProtocols.Mqtt)
{
await _connectionHandler.OnConnectedAsync(connection);
await _connectionHandler.OnConnectedAsync(connection).ConfigureAwait(false);
}
else if (protocols == MqttProtocols.WebSocket)
{
await next(connection);
await next(connection).ConfigureAwait(false);
}
else
{
Expand Down

0 comments on commit ee4de82

Please sign in to comment.