|
| 1 | +//------------------------------------------------------------------------------ |
| 2 | +// <auto-generated> |
| 3 | +// This code was generated by AsyncGenerator. |
| 4 | +// |
| 5 | +// Changes to this file may cause incorrect behavior and will be lost if |
| 6 | +// the code is regenerated. |
| 7 | +// </auto-generated> |
| 8 | +//------------------------------------------------------------------------------ |
| 9 | + |
| 10 | + |
| 11 | +using System.Data; |
| 12 | +using System.Data.Common; |
| 13 | +using NHibernate.AdoNet; |
| 14 | +using NHibernate.SqlTypes; |
| 15 | +using NHibernate.Util; |
| 16 | + |
| 17 | +namespace NHibernate.Driver |
| 18 | +{ |
| 19 | + using System.Threading.Tasks; |
| 20 | + using System.Threading; |
| 21 | + public static partial class DriverExtensions |
| 22 | + { |
| 23 | + |
| 24 | + // 6.0 TODO: merge into IDriver |
| 25 | + /// <summary> |
| 26 | + /// Executes the command and returns a <see cref="DbDataReader"/>. |
| 27 | + /// </summary> |
| 28 | + /// <param name="driver">The driver.</param> |
| 29 | + /// <param name="command">The command to execute.</param> |
| 30 | + /// <param name="cancellationToken">A cancellation token that can be used to cancel the work</param> |
| 31 | + /// <returns>A DbDataReader</returns> |
| 32 | + public static Task<DbDataReader> ExecuteReaderAsync(this IDriver driver, DbCommand command, CancellationToken cancellationToken) |
| 33 | + { |
| 34 | + if (cancellationToken.IsCancellationRequested) |
| 35 | + { |
| 36 | + return Task.FromCanceled<DbDataReader>(cancellationToken); |
| 37 | + } |
| 38 | + try |
| 39 | + { |
| 40 | + return driver is DriverBase driverBase ? driverBase.ExecuteReaderAsync(command, cancellationToken) : command.ExecuteReaderAsync(cancellationToken); |
| 41 | + } |
| 42 | + catch (System.Exception ex) |
| 43 | + { |
| 44 | + return Task.FromException<DbDataReader>(ex); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + } |
| 49 | +} |
0 commit comments