Skip to content

Commit fb2e682

Browse files
committed
Remove unnecessary ConfigureAwait
1 parent 8b01df4 commit fb2e682

File tree

6 files changed

+30
-10
lines changed

6 files changed

+30
-10
lines changed

projects/RabbitMQ.Client/client/TaskExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static async Task DoTimeoutAfter(Task task, TimeSpan timeout)
6565
using (var cts = new CancellationTokenSource())
6666
{
6767
Task delayTask = Task.Delay(timeout, cts.Token);
68-
Task resultTask = await Task.WhenAny(task, delayTask);
68+
Task resultTask = await Task.WhenAny(task, delayTask).ConfigureAwait(false);
6969
if (resultTask == delayTask)
7070
{
7171
Task supressErrorTask = task.ContinueWith(

projects/RabbitMQ.Client/client/api/ITcpClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public interface ITcpClient : IDisposable
1818

1919
Socket Client { get; }
2020

21+
// TODO CancellationToken
2122
Task ConnectAsync(string host, int port);
23+
// TODO CancellationToken
2224
Task ConnectAsync(IPAddress host, int port);
2325

2426
NetworkStream GetStream();

projects/RabbitMQ.Client/client/api/TcpClientAdapter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ await ConnectAsync(ep, port)
3434
.ConfigureAwait(false);
3535
}
3636

37-
public virtual Task ConnectAsync(IPAddress ep, int port)
37+
public virtual async Task ConnectAsync(IPAddress ep, int port)
3838
{
3939
AssertSocket();
40-
return _sock.ConnectAsync(ep, port);
40+
await _sock.ConnectAsync(ep, port)
41+
.ConfigureAwait(false);
4142
}
4243

4344
public virtual void Close()

projects/RabbitMQ.Client/client/impl/Connection.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,12 @@ internal void TakeOver(Connection other)
213213

214214
internal IConnection Open()
215215
{
216-
return OpenAsync()
217-
.ConfigureAwait(false).GetAwaiter().GetResult();
216+
/*
217+
* https://devblogs.microsoft.com/dotnet/configureawait-faq/
218+
* I'm using GetAwaiter().GetResult(). Do I need to use ConfigureAwait(false)?
219+
* Answer: No
220+
*/
221+
return OpenAsync().GetAwaiter().GetResult();
218222
}
219223

220224
internal async ValueTask<IConnection> OpenAsync()
@@ -526,7 +530,12 @@ internal void Write(RentedMemory frames)
526530
ValueTask task = _frameHandler.WriteAsync(frames);
527531
if (!task.IsCompletedSuccessfully)
528532
{
529-
task.ConfigureAwait(false).GetAwaiter().GetResult();
533+
/*
534+
* https://devblogs.microsoft.com/dotnet/configureawait-faq/
535+
* I'm using GetAwaiter().GetResult(). Do I need to use ConfigureAwait(false)?
536+
* Answer: No
537+
*/
538+
task.GetAwaiter().GetResult();
530539
}
531540
}
532541

projects/RabbitMQ.Client/client/impl/SocketFrameHandler.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,12 @@ public TimeSpan WriteTimeout
183183

184184
public void Close()
185185
{
186-
CloseAsync().ConfigureAwait(false).GetAwaiter().GetResult();
186+
/*
187+
* https://devblogs.microsoft.com/dotnet/configureawait-faq/
188+
* I'm using GetAwaiter().GetResult(). Do I need to use ConfigureAwait(false)?
189+
* Answer: No
190+
*/
191+
CloseAsync().GetAwaiter().GetResult();
187192
}
188193

189194
public async ValueTask CloseAsync()
@@ -336,7 +341,6 @@ private void ConnectOrFail(ITcpClient socket, IPEndPoint endpoint, TimeSpan time
336341
{
337342
socket.ConnectAsync(endpoint.Address, endpoint.Port)
338343
.TimeoutAfter(timeout)
339-
.ConfigureAwait(false)
340344
// this ensures exceptions aren't wrapped in an AggregateException
341345
.GetAwaiter()
342346
.GetResult();

projects/Test/SequentialIntegration/TestConnectionRecoveryBase.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,12 @@ internal void RestartServerAndWaitForRecovery(AutorecoveringConnection conn)
255255
protected bool WaitForConfirms(IChannel m)
256256
{
257257
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(4));
258-
return m.WaitForConfirmsAsync(cts.Token)
259-
.ConfigureAwait(false).GetAwaiter().GetResult();
258+
/*
259+
* https://devblogs.microsoft.com/dotnet/configureawait-faq/
260+
* I'm using GetAwaiter().GetResult(). Do I need to use ConfigureAwait(false)?
261+
* Answer: No
262+
*/
263+
return m.WaitForConfirmsAsync(cts.Token).GetAwaiter().GetResult();
260264
}
261265

262266
protected void WaitForRecovery()

0 commit comments

Comments
 (0)