Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change IResettableService.ResetStateAsync() to return Task #16761

Merged
merged 1 commit into from
Jul 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public virtual void ResetState()
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual ValueTask ResetStateAsync()
/// <param name="cancellationToken"> A <see cref="CancellationToken" /> to observe while waiting for the task to complete. </param>
public virtual Task ResetStateAsync(CancellationToken cancellationToken = default)
{
ResetState();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ public virtual void ResetState()
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual ValueTask ResetStateAsync()
/// <param name="cancellationToken"> A <see cref="CancellationToken" /> to observe while waiting for the task to complete. </param>
public virtual Task ResetStateAsync(CancellationToken cancellationToken = default)
{
ResetState();

Expand Down
2 changes: 1 addition & 1 deletion src/EFCore.Relational/Storage/RelationalConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ private bool ShouldClose()

void IResettableService.ResetState() => Dispose();

ValueTask IResettableService.ResetStateAsync() => DisposeAsync();
Task IResettableService.ResetStateAsync(CancellationToken cancellationToken) => DisposeAsync().AsTask();

/// <summary>
/// Gets a semaphore used to serialize access to this connection.
Expand Down
3 changes: 2 additions & 1 deletion src/EFCore/ChangeTracking/ChangeTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.ChangeTracking.Internal;
Expand Down Expand Up @@ -380,7 +381,7 @@ void IResettableService.ResetState()
DeleteOrphansTiming = CascadeTiming.Immediate;
}

ValueTask IResettableService.ResetStateAsync()
Task IResettableService.ResetStateAsync(CancellationToken cancellationToken)
{
((IResettableService)this).ResetState();

Expand Down
3 changes: 2 additions & 1 deletion src/EFCore/ChangeTracking/Internal/StateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,8 @@ public virtual void ResetState()
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual ValueTask ResetStateAsync()
/// <param name="cancellationToken"> A <see cref="CancellationToken" /> to observe while waiting for the task to complete. </param>
public virtual Task ResetStateAsync(CancellationToken cancellationToken = default)
{
ResetState();

Expand Down
7 changes: 4 additions & 3 deletions src/EFCore/DbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ void IDbContextPoolable.Resurrect(DbContextPoolConfigurationSnapshot configurati
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
void IDbContextPoolable.ResetState()
void IResettableService.ResetState()
{
foreach (var service in GetResettableServices())
{
Expand All @@ -677,11 +677,12 @@ void IDbContextPoolable.ResetState()
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
async ValueTask IDbContextPoolable.ResetStateAsync()
/// <param name="cancellationToken"> A <see cref="CancellationToken" /> to observe while waiting for the task to complete. </param>
async Task IResettableService.ResetStateAsync(CancellationToken cancellationToken)
{
foreach (var service in GetResettableServices())
{
await service.ResetStateAsync();
await service.ResetStateAsync(cancellationToken);
}

_disposed = true;
Expand Down
4 changes: 3 additions & 1 deletion src/EFCore/Infrastructure/IResettableService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;

Expand Down Expand Up @@ -33,7 +34,8 @@ public interface IResettableService
/// <summary>
/// Resets the service so that it can be used from the pool.
/// </summary>
/// <param name="cancellationToken"> A <see cref="CancellationToken" /> to observe while waiting for the task to complete. </param>
/// <returns> A task that represents the asynchronous operation. </returns>
ValueTask ResetStateAsync();
Task ResetStateAsync(CancellationToken cancellationToken = default);
}
}
20 changes: 2 additions & 18 deletions src/EFCore/Internal/IDbContextPoolable.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Microsoft.EntityFrameworkCore.Internal
{
Expand All @@ -12,7 +12,7 @@ namespace Microsoft.EntityFrameworkCore.Internal
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public interface IDbContextPoolable
public interface IDbContextPoolable : IResettableService
{
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand All @@ -37,21 +37,5 @@ public interface IDbContextPoolable
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
void Resurrect([NotNull] DbContextPoolConfigurationSnapshot configurationSnapshot);

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
void ResetState();

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
ValueTask ResetStateAsync();
}
}
3 changes: 2 additions & 1 deletion src/EFCore/Internal/InternalDbSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@ IServiceProvider IInfrastructure<IServiceProvider>.Instance
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
ValueTask IResettableService.ResetStateAsync()
/// <param name="cancellationToken"> A <see cref="CancellationToken" /> to observe while waiting for the task to complete. </param>
Task IResettableService.ResetStateAsync(CancellationToken cancellationToken)
{
((IResettableService)this).ResetState();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void ResetState()
{
}

public ValueTask ResetStateAsync() => default;
public Task ResetStateAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;

public IDbContextTransaction BeginTransaction()
{
Expand Down
2 changes: 1 addition & 1 deletion test/EFCore.Relational.Tests/RelationalEventIdTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public Task<bool> OpenAsync(CancellationToken cancellationToken, bool errorsExpe
throw new NotImplementedException();

public void ResetState() => throw new NotImplementedException();
public ValueTask ResetStateAsync() => throw new NotImplementedException();
public Task ResetStateAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException();

public void RollbackTransaction() => throw new NotImplementedException();
public IDbContextTransaction UseTransaction(DbTransaction transaction) => throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public void ResetState()
{
}

public ValueTask ResetStateAsync() => default;
public Task ResetStateAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;

public IDbContextTransaction BeginTransaction() => throw new NotImplementedException();

Expand Down
2 changes: 1 addition & 1 deletion test/EFCore.Tests/DatabaseFacadeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public Task<IDbContextTransaction> BeginTransactionAsync(CancellationToken cance
public void EnlistTransaction(Transaction transaction) => throw new NotImplementedException();

public void ResetState() => throw new NotImplementedException();
public ValueTask ResetStateAsync() => throw new NotImplementedException();
public Task ResetStateAsync(CancellationToken cancellationToken = default) => throw new NotImplementedException();
}

private class FakeDbContextTransaction : IDbContextTransaction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public void ResetState()
{
}

public ValueTask ResetStateAsync() => default;
public Task ResetStateAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;
}

private static DbContext CreateContext(IServiceProvider serviceProvider)
Expand Down
2 changes: 1 addition & 1 deletion test/EFCore.Tests/TestUtilities/FakeStateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void ResetState()
{
}

public ValueTask ResetStateAsync() => default;
public Task ResetStateAsync(CancellationToken cancellationToken = default) => Task.CompletedTask;

public void Unsubscribe()
{
Expand Down