Added ConfigureAwait to (hopefully) all awaits

Ugly as heck, but it's recommended for libraries
This commit is contained in:
Mark van Renswoude 2024-04-08 14:20:15 +02:00
parent db9e957726
commit a0c9d97694
23 changed files with 215 additions and 211 deletions

View File

@ -44,27 +44,26 @@ namespace Tapeti.Flow.SQL
{
return await SqlRetryHelper.Execute(async () =>
{
using (var connection = await GetConnection())
using var connection = await GetConnection().ConfigureAwait(false);
var flowQuery = new SqlCommand($"select FlowID, CreationTime, StateJson from {tableName}", connection);
var flowReader = await flowQuery.ExecuteReaderAsync().ConfigureAwait(false);
var result = new List<FlowRecord<T>>();
while (await flowReader.ReadAsync().ConfigureAwait(false))
{
var flowQuery = new SqlCommand($"select FlowID, CreationTime, StateJson from {tableName}", connection);
var flowReader = await flowQuery.ExecuteReaderAsync();
var flowID = flowReader.GetGuid(0);
var creationTime = flowReader.GetDateTime(1);
var stateJson = flowReader.GetString(2);
var result = new List<FlowRecord<T>>();
while (await flowReader.ReadAsync())
{
var flowID = flowReader.GetGuid(0);
var creationTime = flowReader.GetDateTime(1);
var stateJson = flowReader.GetString(2);
var state = JsonConvert.DeserializeObject<T>(stateJson);
if (state != null)
result.Add(new FlowRecord<T>(flowID, creationTime, state));
}
return result;
var state = JsonConvert.DeserializeObject<T>(stateJson);
if (state != null)
result.Add(new FlowRecord<T>(flowID, creationTime, state));
}
});
return result;
}).ConfigureAwait(false);
}
/// <inheritdoc />
@ -72,23 +71,22 @@ namespace Tapeti.Flow.SQL
{
await SqlRetryHelper.Execute(async () =>
{
using (var connection = await GetConnection())
{
var query = new SqlCommand($"insert into {tableName} (FlowID, StateJson, CreationTime)" +
"values (@FlowID, @StateJson, @CreationTime)",
connection);
using var connection = await GetConnection().ConfigureAwait(false);
var flowIDParam = query.Parameters.Add("@FlowID", SqlDbType.UniqueIdentifier);
var stateJsonParam = query.Parameters.Add("@StateJson", SqlDbType.NVarChar);
var creationTimeParam = query.Parameters.Add("@CreationTime", SqlDbType.DateTime2);
var query = new SqlCommand($"insert into {tableName} (FlowID, StateJson, CreationTime)" +
"values (@FlowID, @StateJson, @CreationTime)",
connection);
flowIDParam.Value = flowID;
stateJsonParam.Value = JsonConvert.SerializeObject(state);
creationTimeParam.Value = timestamp;
var flowIDParam = query.Parameters.Add("@FlowID", SqlDbType.UniqueIdentifier);
var stateJsonParam = query.Parameters.Add("@StateJson", SqlDbType.NVarChar);
var creationTimeParam = query.Parameters.Add("@CreationTime", SqlDbType.DateTime2);
await query.ExecuteNonQueryAsync();
}
});
flowIDParam.Value = flowID;
stateJsonParam.Value = JsonConvert.SerializeObject(state);
creationTimeParam.Value = timestamp;
await query.ExecuteNonQueryAsync().ConfigureAwait(false);
}).ConfigureAwait(false);
}
/// <inheritdoc />
@ -96,19 +94,18 @@ namespace Tapeti.Flow.SQL
{
await SqlRetryHelper.Execute(async () =>
{
using (var connection = await GetConnection())
{
var query = new SqlCommand($"update {tableName} set StateJson = @StateJson where FlowID = @FlowID", connection);
using var connection = await GetConnection().ConfigureAwait(false);
var query = new SqlCommand($"update {tableName} set StateJson = @StateJson where FlowID = @FlowID", connection);
var flowIDParam = query.Parameters.Add("@FlowID", SqlDbType.UniqueIdentifier);
var stateJsonParam = query.Parameters.Add("@StateJson", SqlDbType.NVarChar);
var flowIDParam = query.Parameters.Add("@FlowID", SqlDbType.UniqueIdentifier);
var stateJsonParam = query.Parameters.Add("@StateJson", SqlDbType.NVarChar);
flowIDParam.Value = flowID;
stateJsonParam.Value = JsonConvert.SerializeObject(state);
flowIDParam.Value = flowID;
stateJsonParam.Value = JsonConvert.SerializeObject(state);
await query.ExecuteNonQueryAsync();
}
});
await query.ExecuteNonQueryAsync().ConfigureAwait(false);
}).ConfigureAwait(false);
}
/// <inheritdoc />
@ -116,23 +113,22 @@ namespace Tapeti.Flow.SQL
{
await SqlRetryHelper.Execute(async () =>
{
using (var connection = await GetConnection())
{
var query = new SqlCommand($"delete from {tableName} where FlowID = @FlowID", connection);
using var connection = await GetConnection().ConfigureAwait(false);
var flowIDParam = query.Parameters.Add("@FlowID", SqlDbType.UniqueIdentifier);
flowIDParam.Value = flowID;
var query = new SqlCommand($"delete from {tableName} where FlowID = @FlowID", connection);
await query.ExecuteNonQueryAsync();
}
});
var flowIDParam = query.Parameters.Add("@FlowID", SqlDbType.UniqueIdentifier);
flowIDParam.Value = flowID;
await query.ExecuteNonQueryAsync().ConfigureAwait(false);
}).ConfigureAwait(false);
}
private async Task<SqlConnection> GetConnection()
{
var connection = new SqlConnection(connectionString);
await connection.OpenAsync();
await connection.OpenAsync().ConfigureAwait(false);
return connection;
}

View File

@ -27,14 +27,14 @@ namespace Tapeti.Flow.SQL
{
try
{
await callback();
await callback().ConfigureAwait(false);
break;
}
catch (SqlException e)
{
if (SqlExceptionHelper.IsTransientError(e))
{
await Task.Delay(ExponentialBackoff[retryAttempt]);
await Task.Delay(ExponentialBackoff[retryAttempt]).ConfigureAwait(false);
if (retryAttempt < ExponentialBackoff.Length - 1)
retryAttempt++;
}
@ -51,8 +51,8 @@ namespace Tapeti.Flow.SQL
await Execute(async () =>
{
returnValue = await callback();
});
returnValue = await callback().ConfigureAwait(false);
}).ConfigureAwait(false);
return returnValue!;
}

View File

@ -16,7 +16,7 @@ namespace Tapeti.Flow.Default
public async Task Execute(FlowContext context)
{
await onExecute(context);
await onExecute(context).ConfigureAwait(false);
}
}
}

View File

@ -61,8 +61,8 @@ namespace Tapeti.Flow.Default
if (value == null)
throw new InvalidOperationException("Return value should be a Task, not null");
await (Task)value;
await HandleParallelResponse(messageContext);
await ((Task)value).ConfigureAwait(false);
await HandleParallelResponse(messageContext).ConfigureAwait(false);
});
}
else if (context.Result.Info.ParameterType == typeof(ValueTask))
@ -73,8 +73,8 @@ namespace Tapeti.Flow.Default
// ValueTask is a struct and should never be null
throw new UnreachableException("Return value should be a ValueTask, not null");
await (ValueTask)value;
await HandleParallelResponse(messageContext);
await ((ValueTask)value).ConfigureAwait(false);
await HandleParallelResponse(messageContext).ConfigureAwait(false);
});
}
else if (context.Result.Info.ParameterType == typeof(void))
@ -116,8 +116,8 @@ namespace Tapeti.Flow.Default
if (value == null)
throw new InvalidOperationException("Return value should be a Task<IYieldPoint>, not null");
var yieldPoint = await (Task<IYieldPoint>)value;
await HandleYieldPoint(messageContext, yieldPoint);
var yieldPoint = await ((Task<IYieldPoint>)value).ConfigureAwait(false);
await HandleYieldPoint(messageContext, yieldPoint).ConfigureAwait(false);
});
break;
@ -128,8 +128,8 @@ namespace Tapeti.Flow.Default
// ValueTask is a struct and should never be null
throw new UnreachableException("Return value should be a ValueTask<IYieldPoint>, not null");
var yieldPoint = await (ValueTask<IYieldPoint>)value;
await HandleYieldPoint(messageContext, yieldPoint);
var yieldPoint = await ((ValueTask<IYieldPoint>)value).ConfigureAwait(false);
await HandleYieldPoint(messageContext, yieldPoint).ConfigureAwait(false);
});
break;
@ -159,7 +159,7 @@ namespace Tapeti.Flow.Default
{
// IFlowParallelRequest.AddRequest will store the flow immediately
if (!flowPayload.FlowContext.IsStoredOrDeleted())
await flowContext.Store(context.Binding.QueueType == QueueType.Durable);
await flowContext.Store(context.Binding.QueueType == QueueType.Durable).ConfigureAwait(false);
}));
}

View File

@ -16,14 +16,14 @@ namespace Tapeti.Flow.Default
if (!context.TryGet<ControllerMessageContextPayload>(out var controllerPayload))
return;
var flowContext = await EnrichWithFlowContext(context);
var flowContext = await EnrichWithFlowContext(context).ConfigureAwait(false);
if (flowContext?.ContinuationMetadata == null)
return;
if (flowContext.ContinuationMetadata.MethodName != MethodSerializer.Serialize(controllerPayload.Binding.Method))
return;
await next();
await next().ConfigureAwait(false);
}
@ -44,22 +44,22 @@ namespace Tapeti.Flow.Default
// Remove Continuation now because the IYieldPoint result handler will store the new state
flowContext.FlowState.Continuations.Remove(flowContext.ContinuationID);
await next();
await next().ConfigureAwait(false);
if (flowPayload.FlowIsConverging)
{
var flowHandler = flowContext.HandlerContext.Config.DependencyResolver.Resolve<IFlowHandler>();
await flowHandler.Converge(new FlowHandlerContext(context));
await flowHandler.Converge(new FlowHandlerContext(context)).ConfigureAwait(false);
}
}
else
await next();
await next().ConfigureAwait(false);
}
public async ValueTask Cleanup(IMessageContext context, ConsumeResult consumeResult, Func<ValueTask> next)
{
await next();
await next().ConfigureAwait(false);
if (!context.TryGet<ControllerMessageContextPayload>(out var controllerPayload))
return;
@ -78,7 +78,7 @@ namespace Tapeti.Flow.Default
if (!flowContext.IsStoredOrDeleted())
// The exception strategy can set the consume result to Success. Instead, check if the yield point
// was handled. The flow provider ensures we only end up here in case of an exception.
await flowContext.FlowStateLock.DeleteFlowState();
await flowContext.FlowStateLock.DeleteFlowState().ConfigureAwait(false);
flowContext.FlowStateLock.Dispose();
}
@ -100,13 +100,13 @@ namespace Tapeti.Flow.Default
var flowStore = context.Config.DependencyResolver.Resolve<IFlowStore>();
var flowID = await flowStore.FindFlowID(continuationID);
var flowID = await flowStore.FindFlowID(continuationID).ConfigureAwait(false);
if (!flowID.HasValue)
return null;
var flowStateLock = await flowStore.LockFlowState(flowID.Value);
var flowStateLock = await flowStore.LockFlowState(flowID.Value).ConfigureAwait(false);
var flowState = await flowStateLock.GetFlowState();
var flowState = await flowStateLock.GetFlowState().ConfigureAwait(false);
if (flowState == null)
return null;

View File

@ -76,7 +76,7 @@ namespace Tapeti.Flow.Default
{
if (!context.HasFlowStateAndLock)
{
await CreateNewFlowState(context);
await CreateNewFlowState(context).ConfigureAwait(false);
Debug.Assert(context.FlowState != null, "context.FlowState != null");
}
@ -103,10 +103,10 @@ namespace Tapeti.Flow.Default
internal async Task SendRequest(FlowContext context, object message, ResponseHandlerInfo responseHandlerInfo,
string? convergeMethodName = null, bool convergeMethodTaskSync = false)
{
var properties = await PrepareRequest(context, responseHandlerInfo, convergeMethodName, convergeMethodTaskSync);
await context.Store(responseHandlerInfo.IsDurableQueue);
var properties = await PrepareRequest(context, responseHandlerInfo, convergeMethodName, convergeMethodTaskSync).ConfigureAwait(false);
await context.Store(responseHandlerInfo.IsDurableQueue).ConfigureAwait(false);
await publisher.Publish(message, properties, true);
await publisher.Publish(message, properties, true).ConfigureAwait(false);
}
@ -129,17 +129,17 @@ namespace Tapeti.Flow.Default
// TODO disallow if replyto is not specified?
if (reply.ReplyTo != null)
await publisher.PublishDirect(message, reply.ReplyTo, properties, reply.Mandatory);
await publisher.PublishDirect(message, reply.ReplyTo, properties, reply.Mandatory).ConfigureAwait(false);
else
await publisher.Publish(message, properties, reply.Mandatory);
await publisher.Publish(message, properties, reply.Mandatory).ConfigureAwait(false);
await context.Delete();
await context.Delete().ConfigureAwait(false);
}
internal static async Task EndFlow(FlowContext context)
{
await context.Delete();
await context.Delete().ConfigureAwait(false);
if (context is { HasFlowStateAndLock: true, FlowState.Metadata.Reply: { } })
throw new YieldPointException($"Flow must end with a response message of type {context.FlowState.Metadata.Reply.ResponseTypeName}");
@ -194,7 +194,7 @@ namespace Tapeti.Flow.Default
var flowStore = flowContext.HandlerContext.Config.DependencyResolver.Resolve<IFlowStore>();
var flowID = Guid.NewGuid();
var flowStateLock = await flowStore.LockFlowState(flowID);
var flowStateLock = await flowStore.LockFlowState(flowID).ConfigureAwait(false);
if (flowStateLock == null)
throw new InvalidOperationException("Unable to lock a new flow");
@ -232,7 +232,7 @@ namespace Tapeti.Flow.Default
try
{
await executableYieldPoint.Execute(flowContext);
await executableYieldPoint.Execute(flowContext).ConfigureAwait(false);
}
catch (YieldPointException e)
{
@ -272,7 +272,7 @@ namespace Tapeti.Flow.Default
if (flowContext.ContinuationMetadata.ConvergeMethodName == null)
throw new InvalidOperationException("Missing ConvergeMethodName in FlowContext ContinuationMetadata");
await Converge(flowContext, flowContext.ContinuationMetadata.ConvergeMethodName, flowContext.ContinuationMetadata.ConvergeMethodSync);
await Converge(flowContext, flowContext.ContinuationMetadata.ConvergeMethodName, flowContext.ContinuationMetadata.ConvergeMethodSync).ConfigureAwait(false);
}));
}
@ -305,13 +305,13 @@ namespace Tapeti.Flow.Default
if (yieldPointTask == null)
throw new YieldPointException($"Yield point is required in controller {controllerPayload.Controller.GetType().Name} for converge method {convergeMethodName}");
yieldPoint = await (Task<IYieldPoint>)yieldPointTask;
yieldPoint = await ((Task<IYieldPoint>)yieldPointTask).ConfigureAwait(false);
}
if (yieldPoint == null)
throw new YieldPointException($"Yield point is required in controller {controllerPayload.Controller.GetType().Name} for converge method {convergeMethodName}");
await Execute(flowContext.HandlerContext, yieldPoint);
await Execute(flowContext.HandlerContext, yieldPoint).ConfigureAwait(false);
}
@ -424,13 +424,13 @@ namespace Tapeti.Flow.Default
context,
requestInfo.ResponseHandlerInfo,
convergeMethod.Method.Name,
convergeMethodSync);
convergeMethodSync).ConfigureAwait(false);
preparedRequests.Add(new PreparedRequest(requestInfo.Message, properties));
}
await context.Store(requests.Any(i => i.ResponseHandlerInfo.IsDurableQueue));
await Task.WhenAll(preparedRequests.Select(r => publisher.Publish(r.Message, r.Properties, true)));
await context.Store(requests.Any(i => i.ResponseHandlerInfo.IsDurableQueue)).ConfigureAwait(false);
await Task.WhenAll(preparedRequests.Select(r => publisher.Publish(r.Message, r.Properties, true))).ConfigureAwait(false);
});
}
}

View File

@ -25,25 +25,25 @@ namespace Tapeti.Flow.Default
/// <inheritdoc />
public async Task Start<TController>(Expression<Func<TController, Func<IYieldPoint>>> methodSelector) where TController : class
{
await CallControllerMethod<TController>(GetExpressionMethod(methodSelector), value => Task.FromResult((IYieldPoint)value), Array.Empty<object?>());
await CallControllerMethod<TController>(GetExpressionMethod(methodSelector), value => Task.FromResult((IYieldPoint)value), Array.Empty<object?>()).ConfigureAwait(false);
}
/// <inheritdoc />
public async Task Start<TController>(Expression<Func<TController, Func<Task<IYieldPoint>>>> methodSelector) where TController : class
{
await CallControllerMethod<TController>(GetExpressionMethod(methodSelector), value => (Task<IYieldPoint>)value, Array.Empty<object?>());
await CallControllerMethod<TController>(GetExpressionMethod(methodSelector), value => (Task<IYieldPoint>)value, Array.Empty<object?>()).ConfigureAwait(false);
}
/// <inheritdoc />
public async Task Start<TController, TParameter>(Expression<Func<TController, Func<TParameter, IYieldPoint>>> methodSelector, TParameter parameter) where TController : class
{
await CallControllerMethod<TController>(GetExpressionMethod(methodSelector), value => Task.FromResult((IYieldPoint)value), new object?[] {parameter});
await CallControllerMethod<TController>(GetExpressionMethod(methodSelector), value => Task.FromResult((IYieldPoint)value), new object?[] {parameter}).ConfigureAwait(false);
}
/// <inheritdoc />
public async Task Start<TController, TParameter>(Expression<Func<TController, Func<TParameter, Task<IYieldPoint>>>> methodSelector, TParameter parameter) where TController : class
{
await CallControllerMethod<TController>(GetExpressionMethod(methodSelector), value => (Task<IYieldPoint>)value, new object?[] {parameter});
await CallControllerMethod<TController>(GetExpressionMethod(methodSelector), value => (Task<IYieldPoint>)value, new object?[] {parameter}).ConfigureAwait(false);
}
@ -54,12 +54,12 @@ namespace Tapeti.Flow.Default
if (result == null)
throw new InvalidOperationException($"Method {method.Name} must return an IYieldPoint or Task<IYieldPoint>, got null");
var yieldPoint = await getYieldPointResult(result);
var yieldPoint = await getYieldPointResult(result).ConfigureAwait(false);
var context = new FlowHandlerContext(config, controller, method);
var flowHandler = config.DependencyResolver.Resolve<IFlowHandler>();
await flowHandler.Execute(context, yieldPoint);
await flowHandler.Execute(context, yieldPoint).ConfigureAwait(false);
}

View File

@ -64,7 +64,7 @@ namespace Tapeti.Flow.Default
validatedMethods = new HashSet<string>();
try
{
foreach (var flowStateRecord in await repository.GetStates<FlowState>())
foreach (var flowStateRecord in await repository.GetStates<FlowState>().ConfigureAwait(false))
{
flowStates.TryAdd(flowStateRecord.FlowID, new CachedFlowState(flowStateRecord.FlowState, flowStateRecord.CreationTime, true));
@ -134,7 +134,7 @@ namespace Tapeti.Flow.Default
inUse = true;
var flowStatelock = new FlowStateLock(this, flowID, await locks.GetLock(flowID));
var flowStatelock = new FlowStateLock(this, flowID, await locks.GetLock(flowID).ConfigureAwait(false));
return flowStatelock;
}
@ -215,18 +215,18 @@ namespace Tapeti.Flow.Default
// Storing the flowstate in the underlying repository
if (isNew)
{
await owner.repository.CreateState(FlowID, cachedFlowState.FlowState, cachedFlowState.CreationTime);
await owner.repository.CreateState(FlowID, cachedFlowState.FlowState, cachedFlowState.CreationTime).ConfigureAwait(false);
}
else
{
await owner.repository.UpdateState(FlowID, cachedFlowState.FlowState);
await owner.repository.UpdateState(FlowID, cachedFlowState.FlowState).ConfigureAwait(false);
}
}
else if (wasPersistent)
{
// We transitioned from a durable queue to a dynamic queue,
// remove the persistent state but keep the in-memory version
await owner.repository.DeleteState(FlowID);
await owner.repository.DeleteState(FlowID).ConfigureAwait(false);
}
}
@ -244,7 +244,7 @@ namespace Tapeti.Flow.Default
cachedFlowState = null;
if (removedFlowState is { IsPersistent: true })
await owner.repository.DeleteState(FlowID);
await owner.repository.DeleteState(FlowID).ConfigureAwait(false);
}
}
}

View File

@ -39,7 +39,7 @@ namespace Tapeti.Serilog.Middleware
stopwatch.Start();
await next();
await next().ConfigureAwait(false);
stopwatch.Stop();

View File

@ -32,7 +32,7 @@ namespace Tapeti.Transient
/// <inheritdoc />
public async ValueTask Apply(IBindingTarget target)
{
QueueName = await target.BindDynamicDirect(dynamicQueuePrefix, null);
QueueName = await target.BindDynamicDirect(dynamicQueuePrefix, null).ConfigureAwait(false);
router.TransientResponseQueueName = QueueName;
}

View File

@ -23,7 +23,7 @@ namespace Tapeti.Transient
/// <inheritdoc />
public async Task<TResponse> RequestResponse<TRequest, TResponse>(TRequest request) where TRequest : class where TResponse : class
{
return (TResponse)await router.RequestResponse(publisher, request);
return (TResponse)await router.RequestResponse(publisher, request).ConfigureAwait(false);
}
}
}

View File

@ -71,7 +71,7 @@ namespace Tapeti.Transient
Persistent = false
};
await ((IInternalPublisher)publisher).Publish(request, properties, false);
await ((IInternalPublisher)publisher).Publish(request, properties, false).ConfigureAwait(false);
}
catch (Exception)
{
@ -84,7 +84,7 @@ namespace Tapeti.Transient
await using (new Timer(TimeoutResponse, tcs, defaultTimeoutMs, -1))
{
return await tcs.Task;
return await tcs.Task.ConfigureAwait(false);
}
}

View File

@ -45,7 +45,7 @@ namespace Tapeti.Connection
if (capturedTaskQueue == null)
return;
await capturedTaskQueue.Add(() => { });
await capturedTaskQueue.Add(() => { }).ConfigureAwait(false);
capturedTaskQueue.Dispose();
}
@ -74,7 +74,7 @@ namespace Tapeti.Connection
{
return GetTaskQueue().Add(async () =>
{
await operation(modelProvider);
await operation(modelProvider).ConfigureAwait(false);
});
}

View File

@ -175,7 +175,7 @@ namespace Tapeti.Connection
var delayCancellationTokenSource = new CancellationTokenSource();
var signalledTask = await Task.WhenAny(
publishResultTask,
Task.Delay(MandatoryReturnTimeout, delayCancellationTokenSource.Token));
Task.Delay(MandatoryReturnTimeout, delayCancellationTokenSource.Token)).ConfigureAwait(false);
if (signalledTask != publishResultTask)
throw new TimeoutException(
@ -201,7 +201,7 @@ namespace Tapeti.Connection
throw new NoRouteException(
$"Mandatory message with exchange '{exchange}' and routing key '{routingKey}' could not be delivered, reply code: {replyCode}");
}
});
}).ConfigureAwait(false);
}
@ -226,7 +226,7 @@ namespace Tapeti.Connection
capturedConnectionReference = Interlocked.Read(ref connectionReference);
var basicConsumer = new TapetiBasicConsumer(consumer, capturedConnectionReference, Respond);
consumerTag = channel.BasicConsume(queueName, false, basicConsumer);
});
}).ConfigureAwait(false);
return consumerTag == null
? null
@ -257,7 +257,7 @@ namespace Tapeti.Connection
return;
channel.BasicCancel(consumerTag.ConsumerTag);
});
}).ConfigureAwait(false);
}
@ -291,13 +291,13 @@ namespace Tapeti.Connection
default:
throw new ArgumentOutOfRangeException(nameof(result), result, null);
}
});
}).ConfigureAwait(false);
}
private async Task<bool> GetDurableQueueDeclareRequired(string queueName, IRabbitMQArguments? arguments)
{
var existingQueue = await GetQueueInfo(queueName);
var existingQueue = await GetQueueInfo(queueName).ConfigureAwait(false);
if (existingQueue == null)
return true;
@ -342,9 +342,9 @@ namespace Tapeti.Connection
/// <inheritdoc />
public async Task DurableQueueDeclare(string queueName, IEnumerable<QueueBinding> bindings, IRabbitMQArguments? arguments, CancellationToken cancellationToken)
{
var declareRequired = await GetDurableQueueDeclareRequired(queueName, arguments);
var declareRequired = await GetDurableQueueDeclareRequired(queueName, arguments).ConfigureAwait(false);
var existingBindings = (await GetQueueBindings(queueName)).ToList();
var existingBindings = (await GetQueueBindings(queueName).ConfigureAwait(false)).ToList();
var currentBindings = bindings.ToList();
var bindingLogger = logger as IBindingLogger;
@ -371,7 +371,7 @@ namespace Tapeti.Connection
bindingLogger?.QueueUnbind(queueName, deletedBinding.Exchange, deletedBinding.RoutingKey);
channel.QueueUnbind(queueName, deletedBinding.Exchange, deletedBinding.RoutingKey);
}
});
}).ConfigureAwait(false);
}
@ -386,7 +386,7 @@ namespace Tapeti.Connection
/// <inheritdoc />
public async Task DurableQueueVerify(string queueName, IRabbitMQArguments? arguments, CancellationToken cancellationToken)
{
if (!await GetDurableQueueDeclareRequired(queueName, arguments))
if (!await GetDurableQueueDeclareRequired(queueName, arguments).ConfigureAwait(false))
return;
await GetTapetiChannel(TapetiChannelType.Consume).Queue(channel =>
@ -396,7 +396,7 @@ namespace Tapeti.Connection
(logger as IBindingLogger)?.QueueDeclare(queueName, true, true);
channel.QueueDeclarePassive(queueName);
});
}).ConfigureAwait(false);
}
@ -413,7 +413,7 @@ namespace Tapeti.Connection
return;
deletedMessages = channel.QueueDelete(queueName);
});
}).ConfigureAwait(false);
deletedQueues.Add(queueName);
(logger as IBindingLogger)?.QueueObsolete(queueName, true, deletedMessages);
@ -434,7 +434,7 @@ namespace Tapeti.Connection
// Get queue information from the Management API, since the AMQP operations will
// throw an error if the queue does not exist or still contains messages and resets
// the connection. The resulting reconnect will cause subscribers to reset.
var queueInfo = await GetQueueInfo(queueName);
var queueInfo = await GetQueueInfo(queueName).ConfigureAwait(false);
if (queueInfo == null)
{
deletedQueues.Add(queueName);
@ -467,7 +467,7 @@ namespace Tapeti.Connection
else
{
// Remove all bindings instead
var existingBindings = (await GetQueueBindings(queueName)).ToList();
var existingBindings = (await GetQueueBindings(queueName).ConfigureAwait(false)).ToList();
if (existingBindings.Count > 0)
{
@ -481,7 +481,7 @@ namespace Tapeti.Connection
(logger as IBindingLogger)?.QueueObsolete(queueName, false, queueInfo.Messages);
}
} while (retry);
});
}).ConfigureAwait(false);
}
@ -507,7 +507,7 @@ namespace Tapeti.Connection
queueName = channel.QueueDeclare(arguments: GetDeclareArguments(arguments)).QueueName;
bindingLogger?.QueueDeclare(queueName, false, false);
}
});
}).ConfigureAwait(false);
cancellationToken.ThrowIfCancellationRequested();
if (queueName == null)
@ -527,7 +527,7 @@ namespace Tapeti.Connection
DeclareExchange(channel, binding.Exchange);
(logger as IBindingLogger)?.QueueBind(queueName, false, binding.Exchange, binding.RoutingKey);
channel.QueueBind(queueName, binding.Exchange, binding.RoutingKey);
});
}).ConfigureAwait(false);
}
@ -551,8 +551,8 @@ namespace Tapeti.Connection
}
// Empty the queue
await consumeChannel.Reset();
await publishChannel.Reset();
await consumeChannel.Reset().ConfigureAwait(false);
await publishChannel.Reset().ConfigureAwait(false);
// No need to close the channels as the connection will be closed
capturedConsumeModel?.Dispose();
@ -619,9 +619,9 @@ namespace Tapeti.Connection
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
return JsonConvert.DeserializeObject<ManagementQueueInfo>(content);
});
}).ConfigureAwait(false);
}
@ -659,7 +659,7 @@ namespace Tapeti.Connection
{
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
var bindings = JsonConvert.DeserializeObject<IEnumerable<ManagementBinding>>(content);
// Filter out the binding to an empty source, which is always present for direct-to-queue routing
@ -667,7 +667,7 @@ namespace Tapeti.Connection
.Where(binding => !string.IsNullOrEmpty(binding.Source) && !string.IsNullOrEmpty(binding.RoutingKey))
.Select(binding => new QueueBinding(binding.Source!, binding.RoutingKey!))
?? Enumerable.Empty<QueueBinding>();
});
}).ConfigureAwait(false);
}
@ -702,8 +702,8 @@ namespace Tapeti.Connection
{
try
{
var response = await managementClient.SendAsync(request);
return await handleResponse(response);
var response = await managementClient.SendAsync(request).ConfigureAwait(false);
return await handleResponse(response).ConfigureAwait(false);
}
catch (TimeoutException)
{
@ -717,7 +717,7 @@ namespace Tapeti.Connection
throw;
}
await Task.Delay(ExponentialBackoff[retryDelayIndex]);
await Task.Delay(ExponentialBackoff[retryDelayIndex]).ConfigureAwait(false);
if (retryDelayIndex < ExponentialBackoff.Length - 1)
retryDelayIndex++;

View File

@ -60,7 +60,7 @@ namespace Tapeti.Connection
Exchange = exchange,
RoutingKey = routingKey,
Properties = properties
});
}).ConfigureAwait(false);
}
catch (Exception dispatchException)
{
@ -78,7 +78,7 @@ namespace Tapeti.Connection
};
var exceptionContext = new ExceptionStrategyContext(emptyContext, dispatchException);
await HandleException(exceptionContext);
await HandleException(exceptionContext).ConfigureAwait(false);
return exceptionContext.ConsumeResult;
}
@ -93,7 +93,7 @@ namespace Tapeti.Connection
foreach (var binding in bindings.Where(binding => binding.Accept(messageType)))
{
var consumeResult = await InvokeUsingBinding(message, messageContextData, binding);
var consumeResult = await InvokeUsingBinding(message, messageContextData, binding).ConfigureAwait(false);
validMessageType = true;
if (consumeResult != ConsumeResult.Success)
@ -125,18 +125,18 @@ namespace Tapeti.Connection
try
{
await MiddlewareHelper.GoAsync(config.Middleware.Message,
async (handler, next) => await handler.Handle(context, next),
async () => { await binding.Invoke(context); });
async (handler, next) => await handler.Handle(context, next).ConfigureAwait(false),
async () => { await binding.Invoke(context).ConfigureAwait(false); });
await binding.Cleanup(context, ConsumeResult.Success);
await binding.Cleanup(context, ConsumeResult.Success).ConfigureAwait(false);
return ConsumeResult.Success;
}
catch (Exception invokeException)
{
var exceptionContext = new ExceptionStrategyContext(context, invokeException);
await HandleException(exceptionContext);
await HandleException(exceptionContext).ConfigureAwait(false);
await binding.Cleanup(context, exceptionContext.ConsumeResult);
await binding.Cleanup(context, exceptionContext.ConsumeResult).ConfigureAwait(false);
return exceptionContext.ConsumeResult;
}
}
@ -153,7 +153,7 @@ namespace Tapeti.Connection
try
{
await exceptionStrategy.HandleException(exceptionContext);
await exceptionStrategy.HandleException(exceptionContext).ConfigureAwait(false);
}
catch (Exception strategyException)
{

View File

@ -34,21 +34,21 @@ namespace Tapeti.Connection
/// <inheritdoc />
public async Task Publish(object message)
{
await Publish(message, null, IsMandatory(message));
await Publish(message, null, IsMandatory(message)).ConfigureAwait(false);
}
/// <inheritdoc />
public async Task PublishRequest<TController, TRequest, TResponse>(TRequest message, Expression<Func<TController, Action<TResponse>>> responseMethodSelector) where TController : class where TRequest : class where TResponse : class
{
await PublishRequest(message, responseMethodSelector.Body);
await PublishRequest(message, responseMethodSelector.Body).ConfigureAwait(false);
}
/// <inheritdoc />
public async Task PublishRequest<TController, TRequest, TResponse>(TRequest message, Expression<Func<TController, Func<TResponse, Task>>> responseMethodSelector) where TController : class where TRequest : class where TResponse : class
{
await PublishRequest(message, responseMethodSelector.Body);
await PublishRequest(message, responseMethodSelector.Body).ConfigureAwait(false);
}
@ -87,14 +87,14 @@ namespace Tapeti.Connection
ReplyTo = binding.QueueName
};
await Publish(message, properties, IsMandatory(message));
await Publish(message, properties, IsMandatory(message)).ConfigureAwait(false);
}
/// <inheritdoc />
public async Task SendToQueue(string queueName, object message)
{
await PublishDirect(message, queueName, null, IsMandatory(message));
await PublishDirect(message, queueName, null, IsMandatory(message)).ConfigureAwait(false);
}
@ -105,14 +105,14 @@ namespace Tapeti.Connection
var exchange = exchangeStrategy.GetExchange(messageClass);
var routingKey = routingKeyStrategy.GetRoutingKey(messageClass);
await Publish(message, properties, exchange, routingKey, mandatory);
await Publish(message, properties, exchange, routingKey, mandatory).ConfigureAwait(false);
}
/// <inheritdoc />
public async Task PublishDirect(object message, string queueName, IMessageProperties? properties, bool mandatory)
{
await Publish(message, properties, null, queueName, mandatory);
await Publish(message, properties, null, queueName, mandatory).ConfigureAwait(false);
}
@ -136,12 +136,12 @@ namespace Tapeti.Connection
await MiddlewareHelper.GoAsync(
config.Middleware.Publish,
async (handler, next) => await handler.Handle(context, next),
async (handler, next) => await handler.Handle(context, next).ConfigureAwait(false),
async () =>
{
var body = messageSerializer.Serialize(message, writableProperties);
await clientFactory().Publish(body, writableProperties, exchange, routingKey, mandatory);
});
await clientFactory().Publish(body, writableProperties, exchange, routingKey, mandatory).ConfigureAwait(false);
}).ConfigureAwait(false);
}

View File

@ -29,7 +29,7 @@ namespace Tapeti.Connection
public async ValueTask DisposeAsync()
{
if (consuming)
await Stop();
await Stop().ConfigureAwait(false);
}
@ -48,7 +48,7 @@ namespace Tapeti.Connection
public async Task ApplyBindings()
{
initializeCancellationTokenSource = new CancellationTokenSource();
await ApplyBindings(initializeCancellationTokenSource.Token);
await ApplyBindings(initializeCancellationTokenSource.Token).ConfigureAwait(false);
}
@ -81,10 +81,10 @@ namespace Tapeti.Connection
Task.Run(async () =>
{
await ApplyBindings(cancellationToken);
await ApplyBindings(cancellationToken).ConfigureAwait(false);
if (consuming && !cancellationToken.IsCancellationRequested)
await ConsumeQueues(cancellationToken);
await ConsumeQueues(cancellationToken).ConfigureAwait(false);
}, CancellationToken.None);
}
@ -98,7 +98,7 @@ namespace Tapeti.Connection
consuming = true;
initializeCancellationTokenSource = new CancellationTokenSource();
await ConsumeQueues(initializeCancellationTokenSource.Token);
await ConsumeQueues(initializeCancellationTokenSource.Token).ConfigureAwait(false);
}
@ -111,7 +111,7 @@ namespace Tapeti.Connection
initializeCancellationTokenSource?.Cancel();
initializeCancellationTokenSource = null;
await Task.WhenAll(consumerTags.Select(async tag => await clientFactory().Cancel(tag)));
await Task.WhenAll(consumerTags.Select(async tag => await clientFactory().Cancel(tag))).ConfigureAwait(false);
consumerTags.Clear();
consuming = false;
@ -133,9 +133,9 @@ namespace Tapeti.Connection
bindingTarget = new NoVerifyBindingTarget(clientFactory, routingKeyStrategy, exchangeStrategy, cancellationToken);
foreach (var binding in config.Bindings)
await binding.Apply(bindingTarget);
await binding.Apply(bindingTarget).ConfigureAwait(false);
await bindingTarget.Apply();
await bindingTarget.Apply().ConfigureAwait(false);
}
@ -155,8 +155,8 @@ namespace Tapeti.Connection
var queueName = group.Key;
var consumer = new TapetiConsumer(cancellationToken, config, queueName, group);
return await clientFactory().Consume(queueName, consumer, cancellationToken);
})))
return await clientFactory().Consume(queueName, consumer, cancellationToken).ConfigureAwait(false);
})).ConfigureAwait(false))
.Where(t => t?.ConsumerTag != null)
.Cast<TapetiConsumerTag>());
}
@ -201,14 +201,14 @@ namespace Tapeti.Connection
public async ValueTask<string> BindDynamic(Type messageClass, string? queuePrefix, IRabbitMQArguments? arguments)
{
var result = await DeclareDynamicQueue(messageClass, queuePrefix, arguments);
var result = await DeclareDynamicQueue(messageClass, queuePrefix, arguments).ConfigureAwait(false);
if (!result.IsNewMessageClass)
return result.QueueName;
var routingKey = RoutingKeyStrategy.GetRoutingKey(messageClass);
var exchange = ExchangeStrategy.GetExchange(messageClass);
await ClientFactory().DynamicQueueBind(result.QueueName, new QueueBinding(exchange, routingKey), CancellationToken);
await ClientFactory().DynamicQueueBind(result.QueueName, new QueueBinding(exchange, routingKey), CancellationToken).ConfigureAwait(false);
return result.QueueName;
}
@ -216,7 +216,7 @@ namespace Tapeti.Connection
public async ValueTask<string> BindDynamicDirect(Type messageClass, string? queuePrefix, IRabbitMQArguments? arguments)
{
var result = await DeclareDynamicQueue(messageClass, queuePrefix, arguments);
var result = await DeclareDynamicQueue(messageClass, queuePrefix, arguments).ConfigureAwait(false);
return result.QueueName;
}
@ -225,7 +225,7 @@ namespace Tapeti.Connection
{
// If we don't know the routing key, always create a new queue to ensure there is no overlap.
// Keep it out of the dynamicQueues dictionary, so it can't be re-used later on either.
return await ClientFactory().DynamicQueueDeclare(queuePrefix, arguments, CancellationToken);
return await ClientFactory().DynamicQueueDeclare(queuePrefix, arguments, CancellationToken).ConfigureAwait(false);
}
@ -267,7 +267,7 @@ namespace Tapeti.Connection
}
// Declare a new queue
var queueName = await ClientFactory().DynamicQueueDeclare(queuePrefix, arguments, CancellationToken);
var queueName = await ClientFactory().DynamicQueueDeclare(queuePrefix, arguments, CancellationToken).ConfigureAwait(false);
var queueInfo = new DynamicQueueInfo
{
QueueName = queueName,
@ -363,8 +363,8 @@ namespace Tapeti.Connection
public override async Task Apply()
{
var client = ClientFactory();
await DeclareQueues(client);
await DeleteObsoleteQueues(client);
await DeclareQueues(client).ConfigureAwait(false);
await DeleteObsoleteQueues(client).ConfigureAwait(false);
}
@ -380,8 +380,8 @@ namespace Tapeti.Connection
return new QueueBinding(exchange, routingKey);
});
await client.DurableQueueDeclare(queue.Key, bindings, queue.Value.Arguments, CancellationToken);
}));
await client.DurableQueueDeclare(queue.Key, bindings, queue.Value.Arguments, CancellationToken).ConfigureAwait(false);
})).ConfigureAwait(false);
}
@ -389,8 +389,8 @@ namespace Tapeti.Connection
{
await Task.WhenAll(obsoleteDurableQueues.Except(durableQueues.Keys).Select(async queue =>
{
await client.DurableQueueDelete(queue, true, CancellationToken);
}));
await client.DurableQueueDelete(queue, true, CancellationToken).ConfigureAwait(false);
})).ConfigureAwait(false);
}
}
@ -407,12 +407,12 @@ namespace Tapeti.Connection
public override async ValueTask BindDurable(Type messageClass, string queueName, IRabbitMQArguments? arguments)
{
await VerifyDurableQueue(queueName, arguments);
await VerifyDurableQueue(queueName, arguments).ConfigureAwait(false);
}
public override async ValueTask BindDurableDirect(string queueName, IRabbitMQArguments? arguments)
{
await VerifyDurableQueue(queueName, arguments);
await VerifyDurableQueue(queueName, arguments).ConfigureAwait(false);
}
public override ValueTask BindDurableObsolete(string queueName)
@ -426,7 +426,7 @@ namespace Tapeti.Connection
if (!durableQueues.Add(queueName))
return;
await ClientFactory().DurableQueueVerify(queueName, arguments, CancellationToken);
await ClientFactory().DurableQueueVerify(queueName, arguments, CancellationToken).ConfigureAwait(false);
}
}

View File

@ -117,10 +117,10 @@ namespace Tapeti.Default
{
case BindingTargetMode.Default:
if (bindingInfo.QueueInfo.QueueType == Config.QueueType.Dynamic)
QueueName = await target.BindDynamic(bindingInfo.MessageClass, bindingInfo.QueueInfo.Name, bindingInfo.QueueInfo.QueueArguments);
QueueName = await target.BindDynamic(bindingInfo.MessageClass, bindingInfo.QueueInfo.Name, bindingInfo.QueueInfo.QueueArguments).ConfigureAwait(false);
else
{
await target.BindDurable(bindingInfo.MessageClass, bindingInfo.QueueInfo.Name!, bindingInfo.QueueInfo.QueueArguments);
await target.BindDurable(bindingInfo.MessageClass, bindingInfo.QueueInfo.Name!, bindingInfo.QueueInfo.QueueArguments).ConfigureAwait(false);
QueueName = bindingInfo.QueueInfo.Name;
}
@ -128,10 +128,10 @@ namespace Tapeti.Default
case BindingTargetMode.Direct:
if (bindingInfo.QueueInfo.QueueType == Config.QueueType.Dynamic)
QueueName = await target.BindDynamicDirect(bindingInfo.MessageClass, bindingInfo.QueueInfo.Name, bindingInfo.QueueInfo.QueueArguments);
QueueName = await target.BindDynamicDirect(bindingInfo.MessageClass, bindingInfo.QueueInfo.Name, bindingInfo.QueueInfo.QueueArguments).ConfigureAwait(false);
else
{
await target.BindDurableDirect(bindingInfo.QueueInfo.Name!, bindingInfo.QueueInfo.QueueArguments);
await target.BindDurableDirect(bindingInfo.QueueInfo.Name!, bindingInfo.QueueInfo.QueueArguments).ConfigureAwait(false);
QueueName = bindingInfo.QueueInfo.Name;
}
@ -143,7 +143,7 @@ namespace Tapeti.Default
}
else if (bindingInfo.QueueInfo.QueueType == Config.QueueType.Durable)
{
await target.BindDurableObsolete(bindingInfo.QueueInfo.Name!);
await target.BindDurableObsolete(bindingInfo.QueueInfo.Name!).ConfigureAwait(false);
QueueName = bindingInfo.QueueInfo.Name;
}
}
@ -165,14 +165,14 @@ namespace Tapeti.Default
var controller = Method.IsStatic ? null : dependencyResolver.Resolve(bindingInfo.ControllerType);
context.Store(new ControllerMessageContextPayload(controller, (IControllerMethodBinding)context.Binding));
if (!await FilterAllowed(context))
if (!await FilterAllowed(context).ConfigureAwait(false))
return;
await MiddlewareHelper.GoAsync(
bindingInfo.MessageMiddleware,
async (handler, next) => await handler.Handle(context, next),
async () => await messageHandler(context));
async (handler, next) => await handler.Handle(context, next).ConfigureAwait(false),
async () => await messageHandler(context).ConfigureAwait(false)).ConfigureAwait(false);
}
@ -181,8 +181,8 @@ namespace Tapeti.Default
{
await MiddlewareHelper.GoAsync(
bindingInfo.CleanupMiddleware,
async (handler, next) => await handler.Cleanup(context, consumeResult, next),
() => default);
async (handler, next) => await handler.Cleanup(context, consumeResult, next).ConfigureAwait(false),
() => default).ConfigureAwait(false);
}
@ -191,12 +191,12 @@ namespace Tapeti.Default
var allowed = false;
await MiddlewareHelper.GoAsync(
bindingInfo.FilterMiddleware,
async (handler, next) => await handler.Filter(context, next),
async (handler, next) => await handler.Filter(context, next).ConfigureAwait(false),
() =>
{
allowed = true;
return default;
});
}).ConfigureAwait(false);
return allowed;
}

View File

@ -79,7 +79,7 @@ namespace Tapeti.Default
switch (payload)
{
case IAsyncDisposable asyncDisposable:
await asyncDisposable.DisposeAsync();
await asyncDisposable.DisposeAsync().ConfigureAwait(false);
break;
case IDisposable disposable:
@ -151,7 +151,7 @@ namespace Tapeti.Default
foreach (var item in items.Values)
{
if (item is IAsyncDisposable asyncDisposable)
await asyncDisposable.DisposeAsync();
await asyncDisposable.DisposeAsync().ConfigureAwait(false);
}
}
}

View File

@ -75,15 +75,15 @@ namespace Tapeti.Default
private static async ValueTask PublishGenericTaskResult<T>(IMessageContext messageContext, object value) where T : class
{
var message = await (Task<T>)value;
await Reply(message, messageContext);
var message = await ((Task<T>)value).ConfigureAwait(false);
await Reply(message, messageContext).ConfigureAwait(false);
}
private static async ValueTask PublishGenericValueTaskResult<T>(IMessageContext messageContext, object value) where T : class
{
var message = await (ValueTask<T>)value;
await Reply(message, messageContext);
var message = await ((ValueTask<T>)value).ConfigureAwait(false);
await Reply(message, messageContext).ConfigureAwait(false);
}
@ -99,9 +99,9 @@ namespace Tapeti.Default
};
if (!string.IsNullOrEmpty(messageContext.Properties.ReplyTo))
await publisher.PublishDirect(message, messageContext.Properties.ReplyTo, properties, messageContext.Properties.Persistent.GetValueOrDefault(true));
await publisher.PublishDirect(message, messageContext.Properties.ReplyTo, properties, messageContext.Properties.Persistent.GetValueOrDefault(true)).ConfigureAwait(false);
else
await publisher.Publish(message, properties, false);
await publisher.Publish(message, properties, false).ConfigureAwait(false);
}
}
}

View File

@ -31,7 +31,7 @@ namespace Tapeti.Default
return;
}
await next();
await next().ConfigureAwait(false);
}
}
}

View File

@ -50,7 +50,7 @@ namespace Tapeti.Helpers
var handlerIndex = middleware?.Count - 1 ?? -1;
if (middleware == null || handlerIndex == -1)
{
await lastHandler();
await lastHandler().ConfigureAwait(false);
return;
}
@ -58,12 +58,12 @@ namespace Tapeti.Helpers
{
handlerIndex--;
if (handlerIndex >= 0)
await handle(middleware[handlerIndex], HandleNext);
await handle(middleware[handlerIndex], HandleNext).ConfigureAwait(false);
else
await lastHandler();
await lastHandler().ConfigureAwait(false);
}
await handle(middleware[handlerIndex], HandleNext);
await handle(middleware[handlerIndex], HandleNext).ConfigureAwait(false);
}
}
}

View File

@ -63,11 +63,11 @@ namespace Tapeti
if (subscriber == null)
{
subscriber = new TapetiSubscriber(() => client.Value, config);
await subscriber.ApplyBindings();
await subscriber.ApplyBindings().ConfigureAwait(false);
}
if (startConsuming)
await subscriber.Resume();
await subscriber.Resume().ConfigureAwait(false);
return subscriber;
}
@ -91,28 +91,36 @@ namespace Tapeti
public async Task Close()
{
if (client.IsValueCreated)
await client.Value.Close();
await client.Value.Close().ConfigureAwait(false);
}
/// <inheritdoc />
public void Dispose()
{
if (!disposed)
DisposeAsync().GetAwaiter().GetResult();
GC.SuppressFinalize(this);
if (disposed)
return;
var disposeAsyncTask = DisposeAsync();
if (!disposeAsyncTask.IsCompleted)
disposeAsyncTask.AsTask().GetAwaiter().GetResult();
}
/// <inheritdoc />
public async ValueTask DisposeAsync()
{
GC.SuppressFinalize(this);
if (disposed)
return;
if (subscriber != null)
await subscriber.DisposeAsync();
await subscriber.DisposeAsync().ConfigureAwait(false);
await Close();
await Close().ConfigureAwait(false);
disposed = true;
}