|
9 | 9 |
|
10 | 10 | namespace Open.Database.Extensions |
11 | 11 | { |
12 | | - public static partial class ChannelExtensions |
| 12 | + [System.Diagnostics.CodeAnalysis.SuppressMessage("Reliability", "CA2012:Use ValueTasks correctly", Justification = "Intentionally running in the background.")] |
| 13 | + public static partial class ChannelDbExtensions |
13 | 14 | { |
14 | | - internal static Channel<T> CreateChannel<T>(int capacity = -1, bool singleReader = false, bool singleWriter = true) |
15 | | - { |
16 | | - if (capacity == 0) throw new ArgumentOutOfRangeException(nameof(capacity), capacity, "Cannot be zero."); |
17 | | - if (capacity < -1) throw new ArgumentOutOfRangeException(nameof(capacity), capacity, "Must greater than zero or equal to negative one (unbounded)."); |
18 | | - |
19 | | - return capacity > 0 |
20 | | - ? Channel.CreateBounded<T>(new BoundedChannelOptions(capacity) |
21 | | - { |
22 | | - SingleWriter = singleWriter, |
23 | | - SingleReader = singleReader, |
24 | | - AllowSynchronousContinuations = true, |
25 | | - FullMode = BoundedChannelFullMode.Wait |
26 | | - }) |
27 | | - : Channel.CreateUnbounded<T>(new UnboundedChannelOptions |
28 | | - { |
29 | | - SingleWriter = singleWriter, |
30 | | - SingleReader = singleReader, |
31 | | - AllowSynchronousContinuations = true |
32 | | - }); |
33 | | - } |
34 | | - |
35 | 15 | /// <summary> |
36 | 16 | /// Iterates an IDataReader and writes each record as an array to an unbound channel. |
37 | 17 | /// Be sure to await the completion. |
@@ -61,16 +41,16 @@ public static ChannelReader<object[]> AsChannel(this IDataReader reader, |
61 | 41 | /// <param name="arrayPool">The array pool to acquire buffers from.</param> |
62 | 42 | /// <param name="cancellationToken">An optional cancellation token.</param> |
63 | 43 | /// <returns>The channel reader containing the results.</returns> |
64 | | - public static ChannelReader<object[]> AsChannel(this IDataReader reader, |
| 44 | + public static ChannelReader<object?[]> AsChannel(this IDataReader reader, |
65 | 45 | bool singleReader, |
66 | | - ArrayPool<object> arrayPool, |
| 46 | + ArrayPool<object?> arrayPool, |
67 | 47 | CancellationToken cancellationToken = default) |
68 | 48 | { |
69 | 49 | if (reader is null) throw new ArgumentNullException(nameof(reader)); |
70 | 50 | if (arrayPool is null) throw new ArgumentNullException(nameof(arrayPool)); |
71 | 51 | Contract.EndContractBlock(); |
72 | 52 |
|
73 | | - var channel = CreateChannel<object[]>(-1, singleReader); |
| 53 | + var channel = CreateChannel<object?[]>(-1, singleReader); |
74 | 54 | _ = ToChannel(reader, channel.Writer, true, arrayPool, cancellationToken); |
75 | 55 | return channel.Reader; |
76 | 56 | } |
@@ -172,16 +152,16 @@ public static ChannelReader<object[]> AsChannel(this IDbCommand command, |
172 | 152 | /// <param name="arrayPool">The array pool to acquire buffers from.</param> |
173 | 153 | /// <param name="cancellationToken">An optional cancellation token.</param> |
174 | 154 | /// <returns>The channel reader containing the results.</returns> |
175 | | - public static ChannelReader<object[]> AsChannel(this IDbCommand command, |
| 155 | + public static ChannelReader<object?[]> AsChannel(this IDbCommand command, |
176 | 156 | bool singleReader, |
177 | | - ArrayPool<object> arrayPool, |
| 157 | + ArrayPool<object?> arrayPool, |
178 | 158 | CancellationToken cancellationToken = default) |
179 | 159 | { |
180 | 160 | if (command is null) throw new ArgumentNullException(nameof(command)); |
181 | 161 | if (arrayPool is null) throw new ArgumentNullException(nameof(arrayPool)); |
182 | 162 | Contract.EndContractBlock(); |
183 | 163 |
|
184 | | - var channel = CreateChannel<object[]>(-1, singleReader); |
| 164 | + var channel = CreateChannel<object?[]>(-1, singleReader); |
185 | 165 | _ = ToChannel(command, channel.Writer, true, arrayPool, cancellationToken); |
186 | 166 | return channel.Reader; |
187 | 167 | } |
@@ -280,15 +260,15 @@ public static ChannelReader<object[]> AsChannel(this IExecuteReader command, |
280 | 260 | /// <param name="singleReader">True will cause the resultant reader to optimize for the assumption that no concurrent read operations will occur.</param> |
281 | 261 | /// <param name="arrayPool">The array pool to acquire buffers from.</param> |
282 | 262 | /// <returns>The channel reader containing the results.</returns> |
283 | | - public static ChannelReader<object[]> AsChannel(this IExecuteReader command, |
| 263 | + public static ChannelReader<object?[]> AsChannel(this IExecuteReader command, |
284 | 264 | bool singleReader, |
285 | | - ArrayPool<object> arrayPool) |
| 265 | + ArrayPool<object?> arrayPool) |
286 | 266 | { |
287 | 267 | if (command is null) throw new ArgumentNullException(nameof(command)); |
288 | 268 | if (arrayPool is null) throw new ArgumentNullException(nameof(arrayPool)); |
289 | 269 | Contract.EndContractBlock(); |
290 | 270 |
|
291 | | - var channel = CreateChannel<object[]>(-1, singleReader); |
| 271 | + var channel = CreateChannel<object?[]>(-1, singleReader); |
292 | 272 | _ = ToChannel(command, channel.Writer, true, arrayPool); |
293 | 273 | return channel.Reader; |
294 | 274 | } |
@@ -386,16 +366,16 @@ public static ChannelReader<object[]> AsChannelAsync(this DbDataReader reader, |
386 | 366 | /// <param name="arrayPool">The array pool to acquire buffers from.</param> |
387 | 367 | /// <param name="cancellationToken">An optional cancellation token.</param> |
388 | 368 | /// <returns>The channel reader containing the results.</returns> |
389 | | - public static ChannelReader<object[]> AsChannelAsync(this DbDataReader reader, |
| 369 | + public static ChannelReader<object?[]> AsChannelAsync(this DbDataReader reader, |
390 | 370 | bool singleReader, |
391 | | - ArrayPool<object> arrayPool, |
| 371 | + ArrayPool<object?> arrayPool, |
392 | 372 | CancellationToken cancellationToken = default) |
393 | 373 | { |
394 | 374 | if (reader is null) throw new ArgumentNullException(nameof(reader)); |
395 | 375 | if (arrayPool is null) throw new ArgumentNullException(nameof(arrayPool)); |
396 | 376 | Contract.EndContractBlock(); |
397 | 377 |
|
398 | | - var channel = CreateChannel<object[]>(-1, singleReader); |
| 378 | + var channel = CreateChannel<object?[]>(-1, singleReader); |
399 | 379 | _ = ToChannelAsync(reader, channel.Writer, true, arrayPool, cancellationToken); |
400 | 380 | return channel.Reader; |
401 | 381 | } |
@@ -497,16 +477,16 @@ public static ChannelReader<object[]> AsChannelAsync(this DbCommand command, |
497 | 477 | /// <param name="arrayPool">The array pool to acquire buffers from.</param> |
498 | 478 | /// <param name="cancellationToken">An optional cancellation token.</param> |
499 | 479 | /// <returns>The channel reader containing the results.</returns> |
500 | | - public static ChannelReader<object[]> AsChannelAsync(this DbCommand command, |
| 480 | + public static ChannelReader<object?[]> AsChannelAsync(this DbCommand command, |
501 | 481 | bool singleReader, |
502 | | - ArrayPool<object> arrayPool, |
| 482 | + ArrayPool<object?> arrayPool, |
503 | 483 | CancellationToken cancellationToken = default) |
504 | 484 | { |
505 | 485 | if (command is null) throw new ArgumentNullException(nameof(command)); |
506 | 486 | if (arrayPool is null) throw new ArgumentNullException(nameof(arrayPool)); |
507 | 487 | Contract.EndContractBlock(); |
508 | 488 |
|
509 | | - var channel = CreateChannel<object[]>(-1, singleReader); |
| 489 | + var channel = CreateChannel<object?[]>(-1, singleReader); |
510 | 490 | _ = ToChannelAsync(command, channel.Writer, true, arrayPool, cancellationToken); |
511 | 491 | return channel.Reader; |
512 | 492 | } |
@@ -605,14 +585,14 @@ public static ChannelReader<object[]> AsChannelAsync(this IExecuteReaderAsync co |
605 | 585 | /// <param name="singleReader">True will cause the resultant reader to optimize for the assumption that no concurrent read operations will occur.</param> |
606 | 586 | /// <param name="arrayPool">The array pool to acquire buffers from.</param> |
607 | 587 | /// <returns>The channel reader containing the results.</returns> |
608 | | - public static ChannelReader<object[]> AsChannelAsync(this IExecuteReaderAsync command, |
| 588 | + public static ChannelReader<object?[]> AsChannelAsync(this IExecuteReaderAsync command, |
609 | 589 | bool singleReader, |
610 | | - ArrayPool<object> arrayPool) |
| 590 | + ArrayPool<object?> arrayPool) |
611 | 591 | { |
612 | 592 | if (command is null) throw new ArgumentNullException(nameof(command)); |
613 | 593 | Contract.EndContractBlock(); |
614 | 594 |
|
615 | | - var channel = CreateChannel<object[]>(-1, singleReader); |
| 595 | + var channel = CreateChannel<object?[]>(-1, singleReader); |
616 | 596 | _ = ToChannelAsync(command, channel.Writer, true, arrayPool); |
617 | 597 | return channel.Reader; |
618 | 598 | } |
|
0 commit comments