-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add missing async methods in System.Data.Common and implement IAsyncDisposable #28596
Comments
Don't think /cc @stephentoub |
|
For most providers, that support pooling, it seems like For MySQL, |
I agree.. It's a question of whether we expect these operations (command cancellation, physical connections) to occur intensively enough, and whether the I/O involved to be light enough, so that ValueTask would have a perf impact. I agree that it probably doesn't make much sense.
Yep, corrected...
I agree, and like with But just as a note, the fact that an operation is usually expected to return synchronously doesn't necessarily seem decisive - both Task- and ValueTask- returning methods can have zero overhead in this case. I think it matters more what happens when the operation does return asynchronously, and how often that's expected to occur. Compare with
I agree... |
Yeah, but then if its instant, you can return a
|
After thinking about this again (and not at 3AM), this doesn't seem to make any sense - finalizers shouldn't be doing I/O or calling async methods, and the classes in question call into the synchronous |
|
Thanks, yes - corrected. |
* new async connection and transaction API * fix NRE * fix DataConnection.Clone constructor * implement async connection/transaction methods support from https://github.com/dotnet/corefx/issues/35012 * revert addition of System.Threading.Tasks.Extensions * fix IndexOutOfRangeException * fix wrong method call * fix implementation, remove BeginTransactionAsync * refactoring and more tests * remove unused method * add more async to new tests * bump travis .net core to 2.1 from 2.0 * disable mono install for travis - we don't use it and it takes a lot of time to setup * disable invalid warning on .net core 2.1 build * fix AccessDatabaseEngine.exe download link
|
Unlike some other async cancellations, cancelling an ongoing database operation typically involves a (potentially) heavy networking operation (e.g. establish a new connection to the database). For this reason it may make sense to treat the cancellation as its own async operation that may need to be cancelled (although I admit it may be a bit contrived). Assuming we decide to keep CancelAsync() (see below), we could drop the cancellation token (although this would be the first case I've heard of where an async method doesn't accept one).
But I do admit it could make sense to not have CancelAsync() at all, and say that Cancel() is there for sync only, whereas sync has the original cancellation token - that does seem to be a simpler API surface around cancellation. @divega what do you think?
For DbDataReader.CloseAsync() - assuming we actually add it (see next point) - it returns ValueTask for consistency with DisposeAsync(), to which it's very similar. Note that unlike with DbConnection, there's no way to reopen a DbDataReader, so disposing and closing really mean the same thing (unless some provider decides to implement them differently). Since DisposeAsync() must return ValueTask (because of IDisposableAsync), it seems to make sense to return the same from CloseAsync(). For DbConnection.CloseAsync(), I think you're right - will update the proposal.
It's definitely not absolutely necessary, but:
|
Just to clarify one of my points from above: in the current state of things, some providers already implement DbCommand.Cancel() via a database-specific mechanism. It should be possible to trigger that same mechanism asynchronously, but if we do that when the cancellation token is triggered we lose the option to pass it down into the socket layer. |
Note: added /cc @divega |
Streams can currently be returned by using |
Because its basically a pass-through? Question on mismatch here then class DbConnection : IAsyncDisposable
{
public virtual Task CloseAsync(CancellationToken cancellationToken = default);
public virtual ValueTask DisposeAsync();
} |
Oh, that is actually new to me (and not supported in Npgsql) - thanks. This makes Have opened npgsql/npgsql#2446 to track adding this to Npgsql, and will remove |
@benaadams my statement above was about Basically:
|
Docs for streaming are at https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sqlclient-streaming-support . The GetFieldValueAsync docs don't list the stream types but i know GetFieldValue supports some stream types. It might be worth verifying the details and seeing if it'd be better to use/extend the existing support or use the new methods you suggest. |
@Wraith2 if you say SqlClient allows |
Regarding cancellation, after thinking about this a bit more I'm convinced we don't need As I wrote above, the main point behind having However, while a socket cancellation makes sense in many scenarios, it doesn't seem to make sense here: if the socket read (or write) for a currently-executing command is cancelled, pending data is left pending but the logic for reading and parsing that data (i.e. So here's a summary of what I think we should have:
I'll update the proposal for now, but any comments on the above are very welcome. |
I'm wrong. GetFieldValue and GetfieldValueAsync will allow XmlReader because I added it (per request) in dotnet/corefx#34880 which was in response to https://github.com/dotnet/corefx/issues/30958 by @bricelam and the reasoning that all field types including streams should be accessible through the same overloads. The same could be done with TextReader and Stream to return binary and text data respectively. There are already GetStream, GetXmlReader and GetTextReader sync versions though so your proposal mirrors those. I think the choice comes down to whether it makes more sense to mirror the existing synchronous api into async versions or whether to take the newer api design permitted by IsDbNull and GetfieldValueAsync. I have no strong feeling either way |
@Wraith2 thanks for testing this. I still think that getting Stream and TextReader via GetFieldValue (and GetFieldValueAsync) makes a lot of sense - there's no real reason for these to be different from other types like string or int. The surface API of DbDataReader is already pretty huge, I'd rather avoid adding more methods than we absolutely have to. |
@roji Remember not all providers are necessarily using |
@ajcvickers it's true that not all providers use socket. However, the proposal is definitely to keep IMHO the question is whether it makes sense to have the ADO.NET API provide two cancellation paths - Do you have a specific scenario/direction in mind? I may be missing something... |
@roji Sorry--I misread. I'm fine with there being no CancelAsync. |
I remember one interesting distinction we discussed with @bricelam while he was working on dotnet/efcore#15001, is that Dispose() is usually implemented to not throw.
Agreed. Should have a new issue on SqlClient to support more stream types with GetFieldValue/GetFieldValueAsync? Should this be covered by ADO.NET specification tests? |
If the area owners are ok with the change then I'll probably pick that up since I did the XmlReader one and know the code in that area. A new tracking issue would be handy. |
Probably worth asking @saurabh500 if he sees any fundamental problem with it. |
Pin dotnet sdk to 3.0.0-preview6 and implement new ADO.NET APIs introduced in .NET Core 3.0: * https://github.com/dotnet/corefx/issues/35564 * https://github.com/dotnet/corefx/issues/35012 Note: we cross-target netcoreapp3.0 since the new APIs aren't yet available in netstandard2.1, but this is expected to happen soon. Fixes npgsql#2481
FYI for all those following, we're proposing to remove the cancellation token from {DbDataReader,DbConnection}.CloseAsync: dotnet/corefx#39070, see discussion in dotnet/standard#1283 (review) |
Pin dotnet sdk to 3.0.0-preview6 and implement new ADO.NET APIs introduced in .NET Core 3.0: * https://github.com/dotnet/corefx/issues/35564 * https://github.com/dotnet/corefx/issues/35012 Note: we cross-target netcoreapp3.0 since the new APIs aren't yet available in netstandard2.1, but this is expected to happen soon. Fixes #2481
* Disable SDL validation (#40903) SDL validation is too expensive to run on a per-build basis. Disable for now * [release/3.0] Update dependencies from dotnet/standard (#40911) * Update dependencies from https://github.com/dotnet/standard build 20190907.2 - NETStandard.Library - 2.1.0-prerelease.19457.2 * Update dependencies from https://github.com/dotnet/standard build 20190907.1 - NETStandard.Library - 2.1.0-prerelease.19457.1 * [release/3.0] Update dependencies from 3 repositories (#40915) * Update dependencies from https://github.com/dotnet/core-setup build 20190907.02 - Microsoft.NETCore.App - 3.0.0-rc2-19457-02 - Microsoft.NETCore.DotNetHost - 3.0.0-rc2-19457-02 - Microsoft.NETCore.DotNetHostPolicy - 3.0.0-rc2-19457-02 * Update dependencies from https://github.com/dotnet/arcade build 20190906.10 - Microsoft.DotNet.XUnitExtensions - 2.4.1-beta.19456.10 - Microsoft.DotNet.XUnitConsoleRunner - 2.5.1-beta.19456.10 - Microsoft.DotNet.VersionTools.Tasks - 1.0.0-beta.19456.10 - Microsoft.DotNet.ApiCompat - 1.0.0-beta.19456.10 - Microsoft.DotNet.Arcade.Sdk - 1.0.0-beta.19456.10 - Microsoft.DotNet.Build.Tasks.Configuration - 1.0.0-beta.19456.10 - Microsoft.DotNet.Build.Tasks.Feed - 2.2.0-beta.19456.10 - Microsoft.DotNet.Build.Tasks.Packaging - 1.0.0-beta.19456.10 - Microsoft.DotNet.CodeAnalysis - 1.0.0-beta.19456.10 - Microsoft.DotNet.CoreFxTesting - 1.0.0-beta.19456.10 - Microsoft.DotNet.GenAPI - 1.0.0-beta.19456.10 - Microsoft.DotNet.GenFacades - 1.0.0-beta.19456.10 - Microsoft.DotNet.Helix.Sdk - 2.0.0-beta.19456.10 - Microsoft.DotNet.RemoteExecutor - 1.0.0-beta.19456.10 * Update dependencies from https://github.com/dotnet/standard build 20190907.5 - NETStandard.Library - 2.1.0-prerelease.19457.5 * Disable ToolboxBitmatAttribute test in netfx (#40901) (#40908) * [release/3.0] Update dependencies from 4 repositories (#40929) * Update dependencies from https://github.com/dotnet/core-setup build 20190907.15 - Microsoft.NETCore.App - 3.0.0-rc2-19457-15 - Microsoft.NETCore.DotNetHost - 3.0.0-rc2-19457-15 - Microsoft.NETCore.DotNetHostPolicy - 3.0.0-rc2-19457-15 * Update dependencies from https://github.com/dotnet/arcade build 20190907.1 - Microsoft.DotNet.XUnitExtensions - 2.4.1-beta.19457.1 - Microsoft.DotNet.XUnitConsoleRunner - 2.5.1-beta.19457.1 - Microsoft.DotNet.VersionTools.Tasks - 1.0.0-beta.19457.1 - Microsoft.DotNet.ApiCompat - 1.0.0-beta.19457.1 - Microsoft.DotNet.Arcade.Sdk - 1.0.0-beta.19457.1 - Microsoft.DotNet.Build.Tasks.Configuration - 1.0.0-beta.19457.1 - Microsoft.DotNet.Build.Tasks.Feed - 2.2.0-beta.19457.1 - Microsoft.DotNet.Build.Tasks.Packaging - 1.0.0-beta.19457.1 - Microsoft.DotNet.CodeAnalysis - 1.0.0-beta.19457.1 - Microsoft.DotNet.CoreFxTesting - 1.0.0-beta.19457.1 - Microsoft.DotNet.GenAPI - 1.0.0-beta.19457.1 - Microsoft.DotNet.GenFacades - 1.0.0-beta.19457.1 - Microsoft.DotNet.Helix.Sdk - 2.0.0-beta.19457.1 - Microsoft.DotNet.RemoteExecutor - 1.0.0-beta.19457.1 * Update dependencies from https://dev.azure.com/dnceng/internal/_git/dotnet-optimization build 20190908.1 - optimization.windows_nt-x64.IBC.CoreFx - 99.99.99-master-20190908.1 * Update dependencies from https://github.com/dotnet/standard build 20190908.3 - NETStandard.Library - 2.1.0-prerelease.19458.3 * [release/3.0] Update dependencies from 4 repositories (#40940) * Update dependencies from https://github.com/dotnet/core-setup build 20190908.11 - Microsoft.NETCore.App - 3.0.0-rc2-19458-11 - Microsoft.NETCore.DotNetHost - 3.0.0-rc2-19458-11 - Microsoft.NETCore.DotNetHostPolicy - 3.0.0-rc2-19458-11 * Update dependencies from https://github.com/dotnet/arcade build 20190908.2 - Microsoft.DotNet.XUnitExtensions - 2.4.1-beta.19458.2 - Microsoft.DotNet.XUnitConsoleRunner - 2.5.1-beta.19458.2 - Microsoft.DotNet.VersionTools.Tasks - 1.0.0-beta.19458.2 - Microsoft.DotNet.ApiCompat - 1.0.0-beta.19458.2 - Microsoft.DotNet.Arcade.Sdk - 1.0.0-beta.19458.2 - Microsoft.DotNet.Build.Tasks.Configuration - 1.0.0-beta.19458.2 - Microsoft.DotNet.Build.Tasks.Feed - 2.2.0-beta.19458.2 - Microsoft.DotNet.Build.Tasks.Packaging - 1.0.0-beta.19458.2 - Microsoft.DotNet.CodeAnalysis - 1.0.0-beta.19458.2 - Microsoft.DotNet.CoreFxTesting - 1.0.0-beta.19458.2 - Microsoft.DotNet.GenAPI - 1.0.0-beta.19458.2 - Microsoft.DotNet.GenFacades - 1.0.0-beta.19458.2 - Microsoft.DotNet.Helix.Sdk - 2.0.0-beta.19458.2 - Microsoft.DotNet.RemoteExecutor - 1.0.0-beta.19458.2 * Update dependencies from https://dev.azure.com/dnceng/internal/_git/dotnet-optimization build 20190909.1 - optimization.windows_nt-x64.IBC.CoreFx - 99.99.99-master-20190909.1 * Update dependencies from https://github.com/dotnet/standard build 20190909.3 - NETStandard.Library - 2.1.0-prerelease.19459.3 * Add missing IAsyncDisposable interfaces to System.Data (#40872) Part of #35012 * Update dependencies from https://github.com/dotnet/coreclr build 20190909.3 (#40956) - Microsoft.NET.Sdk.IL - 3.0.0-rc2.19459.3 - Microsoft.NETCore.ILAsm - 3.0.0-rc2.19459.3 - Microsoft.NETCore.Runtime.CoreCLR - 3.0.0-rc2.19459.3 * Fix TypeConverter for IComponent (#40837) (#40883) * .NET Core 3.0 Prev9 Intellisense nupkg version bump (#40963) (#40965) * [release/3.0] Update dependencies from 4 repositories (#40951) * Update dependencies from https://github.com/dotnet/standard build 20190909.4 - NETStandard.Library - 2.1.0-prerelease.19459.4 * Update dependencies from https://github.com/dotnet/core-setup build 20190909.40 - Microsoft.NETCore.App - 3.0.0-rc2-19459-40 - Microsoft.NETCore.DotNetHost - 3.0.0-rc2-19459-40 - Microsoft.NETCore.DotNetHostPolicy - 3.0.0-rc2-19459-40 * Update dependencies from https://github.com/dotnet/arcade build 20190909.10 - Microsoft.DotNet.XUnitExtensions - 2.4.1-beta.19459.10 - Microsoft.DotNet.XUnitConsoleRunner - 2.5.1-beta.19459.10 - Microsoft.DotNet.VersionTools.Tasks - 1.0.0-beta.19459.10 - Microsoft.DotNet.ApiCompat - 1.0.0-beta.19459.10 - Microsoft.DotNet.Arcade.Sdk - 1.0.0-beta.19459.10 - Microsoft.DotNet.Build.Tasks.Configuration - 1.0.0-beta.19459.10 - Microsoft.DotNet.Build.Tasks.Feed - 2.2.0-beta.19459.10 - Microsoft.DotNet.Build.Tasks.Packaging - 1.0.0-beta.19459.10 - Microsoft.DotNet.CodeAnalysis - 1.0.0-beta.19459.10 - Microsoft.DotNet.CoreFxTesting - 1.0.0-beta.19459.10 - Microsoft.DotNet.GenAPI - 1.0.0-beta.19459.10 - Microsoft.DotNet.GenFacades - 1.0.0-beta.19459.10 - Microsoft.DotNet.Helix.Sdk - 2.0.0-beta.19459.10 - Microsoft.DotNet.RemoteExecutor - 1.0.0-beta.19459.10 * Update dependencies from https://dev.azure.com/dnceng/internal/_git/dotnet-optimization build 20190910.1 - optimization.windows_nt-x64.IBC.CoreFx - 99.99.99-master-20190910.1 * Add test for IComponent typeconverter register in TypeDescriptor (#40959) (#40977) * Update dependencies from https://github.com/dotnet/coreclr build 20190910.2 (#40984) - Microsoft.NET.Sdk.IL - 3.0.0-rc2.19460.2 - Microsoft.NETCore.ILAsm - 3.0.0-rc2.19460.2 - Microsoft.NETCore.Runtime.CoreCLR - 3.0.0-rc2.19460.2 * Update dependencies from https://github.com/dotnet/coreclr build 20190910.4 (#41006) - Microsoft.NET.Sdk.IL - 3.0.0-rc2.19460.4 - Microsoft.NETCore.ILAsm - 3.0.0-rc2.19460.4 - Microsoft.NETCore.Runtime.CoreCLR - 3.0.0-rc2.19460.4 * [release/3.0] Update dependencies from dotnet/arcade dotnet/standard (#40986) * Update dependencies from https://github.com/dotnet/arcade build 20190910.3 - Microsoft.DotNet.XUnitExtensions - 2.4.1-beta.19460.3 - Microsoft.DotNet.XUnitConsoleRunner - 2.5.1-beta.19460.3 - Microsoft.DotNet.VersionTools.Tasks - 1.0.0-beta.19460.3 - Microsoft.DotNet.ApiCompat - 1.0.0-beta.19460.3 - Microsoft.DotNet.Arcade.Sdk - 1.0.0-beta.19460.3 - Microsoft.DotNet.Build.Tasks.Configuration - 1.0.0-beta.19460.3 - Microsoft.DotNet.Build.Tasks.Feed - 2.2.0-beta.19460.3 - Microsoft.DotNet.Build.Tasks.Packaging - 1.0.0-beta.19460.3 - Microsoft.DotNet.CodeAnalysis - 1.0.0-beta.19460.3 - Microsoft.DotNet.CoreFxTesting - 1.0.0-beta.19460.3 - Microsoft.DotNet.GenAPI - 1.0.0-beta.19460.3 - Microsoft.DotNet.GenFacades - 1.0.0-beta.19460.3 - Microsoft.DotNet.Helix.Sdk - 2.0.0-beta.19460.3 - Microsoft.DotNet.RemoteExecutor - 1.0.0-beta.19460.3 * Update dependencies from https://github.com/dotnet/standard build 20190910.4 - NETStandard.Library - 2.1.0-prerelease.19460.4 * Update dependencies from https://github.com/dotnet/standard build 20190910.5 - NETStandard.Library - 2.1.0-prerelease.19460.5 * [release/3.0] Avoid MemoryMarshal.Cast when transcoding from UTF-16 to UTF-8 while escaping in Utf8JsonWriter. (#40997) * Avoid MemoryMarshal.Cast when transcoding from UTF-16 to UTF-8 while escaping in Utf8JsonWriter. * Fix a typo in spacing within the test. * Guard against empty spans where an implementation of JavascriptEncoder might not handle null ptrs correctly. * Cleanup tests to avoid some duplication. * Some more test clean up. * Update dependencies from https://github.com/dotnet/coreclr build 20190910.8 (#41011) - Microsoft.NET.Sdk.IL - 3.0.0-rc2.19460.8 - Microsoft.NETCore.ILAsm - 3.0.0-rc2.19460.8 - Microsoft.NETCore.Runtime.CoreCLR - 3.0.0-rc2.19460.8 * Update dependencies from https://github.com/dotnet/coreclr build 20190910.11 (#41014) - Microsoft.NET.Sdk.IL - 3.0.0-rc2.19460.11 - Microsoft.NETCore.ILAsm - 3.0.0-rc2.19460.11 - Microsoft.NETCore.Runtime.CoreCLR - 3.0.0-rc2.19460.11 * [release/3.0] Update dependencies from 3 repositories (#41022) * Update dependencies from https://github.com/dotnet/core-setup build 20190910.02 - Microsoft.NETCore.App - 3.0.0-rc2-19460-02 - Microsoft.NETCore.DotNetHost - 3.0.0-rc2-19460-02 - Microsoft.NETCore.DotNetHostPolicy - 3.0.0-rc2-19460-02 * Update dependencies from https://dev.azure.com/dnceng/internal/_git/dotnet-optimization build 20190911.1 - optimization.windows_nt-x64.IBC.CoreFx - 99.99.99-master-20190911.1 * Update dependencies from https://github.com/dotnet/standard build 20190911.3 - NETStandard.Library - 2.1.0-prerelease.19461.3 * Update dependencies from https://github.com/dotnet/coreclr build 20190911.3 (#41035) - Microsoft.NET.Sdk.IL - 3.0.0-rc2.19461.3 - Microsoft.NETCore.ILAsm - 3.0.0-rc2.19461.3 - Microsoft.NETCore.Runtime.CoreCLR - 3.0.0-rc2.19461.3 * adding version suffix as non empty for building release package versions * Update dependencies from https://github.com/dotnet/coreclr build 20190911.5 (#41045) - Microsoft.NET.Sdk.IL - 3.0.0-rc2.19461.5 - Microsoft.NETCore.ILAsm - 3.0.0-rc2.19461.5 - Microsoft.NETCore.Runtime.CoreCLR - 3.0.0-rc2.19461.5 * [release/3.0] Update dependencies from 3 repositories (#41052) * Update dependencies from https://github.com/dotnet/arcade build 20190911.7 - Microsoft.DotNet.XUnitExtensions - 2.4.1-beta.19461.7 - Microsoft.DotNet.XUnitConsoleRunner - 2.5.1-beta.19461.7 - Microsoft.DotNet.VersionTools.Tasks - 1.0.0-beta.19461.7 - Microsoft.DotNet.ApiCompat - 1.0.0-beta.19461.7 - Microsoft.DotNet.Arcade.Sdk - 1.0.0-beta.19461.7 - Microsoft.DotNet.Build.Tasks.Configuration - 1.0.0-beta.19461.7 - Microsoft.DotNet.Build.Tasks.Feed - 2.2.0-beta.19461.7 - Microsoft.DotNet.Build.Tasks.Packaging - 1.0.0-beta.19461.7 - Microsoft.DotNet.CodeAnalysis - 1.0.0-beta.19461.7 - Microsoft.DotNet.CoreFxTesting - 1.0.0-beta.19461.7 - Microsoft.DotNet.GenAPI - 1.0.0-beta.19461.7 - Microsoft.DotNet.GenFacades - 1.0.0-beta.19461.7 - Microsoft.DotNet.Helix.Sdk - 2.0.0-beta.19461.7 - Microsoft.DotNet.RemoteExecutor - 1.0.0-beta.19461.7 * Update dependencies from https://dev.azure.com/dnceng/internal/_git/dotnet-optimization build 20190912.1 - optimization.windows_nt-x64.IBC.CoreFx - 99.99.99-master-20190912.1 * Update dependencies from https://github.com/dotnet/standard build 20190912.2 - NETStandard.Library - 2.1.0-prerelease.19462.2 * Update dependencies from https://github.com/dotnet/standard build 20190912.4 - NETStandard.Library - 2.1.0-prerelease.19462.4 * Update dependencies from https://github.com/dotnet/coreclr build 20190912.2 (#41062) - Microsoft.NET.Sdk.IL - 3.0.0-rc2.19462.2 - Microsoft.NETCore.ILAsm - 3.0.0-rc2.19462.2 - Microsoft.NETCore.Runtime.CoreCLR - 3.0.0-rc2.19462.2 * Update dependencies from https://github.com/dotnet/standard build 20190912.5 - NETStandard.Library - 2.1.0 * Stabilize package versions (#41076) * Update dependencies from https://github.com/dotnet/coreclr build 20190912.5 (#41081) - Microsoft.NET.Sdk.IL - 3.0.0-rc2.19462.5 - Microsoft.NETCore.ILAsm - 3.0.0-rc2.19462.5 - Microsoft.NETCore.Runtime.CoreCLR - 3.0.0-rc2.19462.5
Provider implementation tracking issues
Specification
This issue consolidates #18225, #24244.
There are several APIs in System.Data.Common which possibly involve I/O, where we're missing async APIs altogether. This proposal adds these missing APIs, with default implementations that call the sync counterparts - much like the existing async methods on those APIs. In addition, all System.Data.Common types that implement IDisposable would be updated to implement IAsyncDisposable as well.
Note that in other cases async methods already exist but return Task, and we'd like to add overloads returning ValueTask. This is out of scope for this issue (but we'll work on these soon, see #19858, #25297).
This would ideally go into .NET Standard 2.1.
Proposal:
Note that this is only about adding async methods where non currently exist. #25297 is about adding ValueTask overloads where Task-returning async methods already exist (and where we have to think about naming etc.).
Returning Task vs. ValueTask
For the return value of the new proposed methods, our current guiding principle has been to opt for Task when the method in question represents a full database roundtrip operation, where any perf advantages of ValueTask are likely to be dominated by networking etc. Thus, method such as
CommitAsync()
andRollbackAsync()
would return Task (aside from them having no return value).Methods used for processing a resultset being streamed do seem like they'd benefit from returning ValueTask; examples include
DbDataReader.ReadAsync()
,DbDataReader.GetFieldValueAsync<T>()
, which are out of scope of this proposal.Cases such as
DbConnection.CloseAsync()
andDbDataReader.CloseAsync()
seem to be between the two and we could probably go either way with them.It would definitely be good to get some input on this.
Cancellation token overloads
Existing async methods in System.Data.Common come in pairs - a virtual one accepting CancellationToken and a non-virtual one delegating to the first. For the new methods we can just add one method with cancellation token defaulting to
CancellationToken.None
./cc @divega @ajcvickers @terrajobst @stephentoub @bgrainger
Edit history
GetFieldValueAsync<T>()
) already provides this functionality)The text was updated successfully, but these errors were encountered: