diff --git a/Neo4j.Driver/Neo4j.Driver/Public/Extensions/ResultCursorExtensions.cs b/Neo4j.Driver/Neo4j.Driver/Public/Extensions/ResultCursorExtensions.cs
index de078412a..42fee8c9d 100644
--- a/Neo4j.Driver/Neo4j.Driver/Public/Extensions/ResultCursorExtensions.cs
+++ b/Neo4j.Driver/Neo4j.Driver/Public/Extensions/ResultCursorExtensions.cs
@@ -27,19 +27,20 @@ public static class ResultCursorExtensions
{
/// Return the only record in the result stream.
/// The result stream
+ /// A cancellation token that can be used to cancel the asynchronous operation.
/// The only record in the result stream.
///
/// Throws if the result contains more than one record or
/// the result is empty.
///
- public static async Task SingleAsync(this IResultCursor result)
+ public static async Task SingleAsync(this IResultCursor result, CancellationToken cancellationToken = default)
{
if (result == null)
{
throw new ArgumentNullException(nameof(result));
}
- var enumerator = result.GetAsyncEnumerator();
+ var enumerator = result.GetAsyncEnumerator(cancellationToken);
await using (enumerator.ConfigureAwait(false))
{
if (!await enumerator.MoveNextAsync().ConfigureAwait(false))
@@ -60,20 +61,24 @@ public static async Task SingleAsync(this IResultCursor result)
/// Return the only record in the result stream.
/// The result stream
/// The operation to carry out on each record.
+ /// A cancellation token that can be used to cancel the asynchronous operation.
/// The type of the record after specified operation.
/// The only record after specified operation in the result stream.
///
/// Throws if the result contains more than one record or
/// the result is empty.
///
- public static async Task SingleAsync(this IResultCursor result, Func operation)
+ public static async Task SingleAsync(
+ this IResultCursor result,
+ Func operation,
+ CancellationToken cancellationToken = default)
{
if (result == null)
{
throw new ArgumentNullException(nameof(result));
}
- var enumerator = result.GetAsyncEnumerator();
+ var enumerator = result.GetAsyncEnumerator(cancellationToken);
await using (enumerator.ConfigureAwait(false))
{
if (!await enumerator.MoveNextAsync().ConfigureAwait(false))
@@ -138,11 +143,13 @@ public static Task> ToListAsync(this IResultCursor result, Cancell
/// Optional, the driver has no knowledge of the expected result size so use the default
/// constructor: . a capacity can be provided to cost of extending this list.
///
+ /// A cancellation token that can be used to cancel the asynchronous operation.
/// A list of collected operation result.
public static async Task> ToListAsync(
this IResultCursor result,
Func operation,
- int initialCapacity = 0)
+ int initialCapacity = 0,
+ CancellationToken cancellationToken = default)
{
if (result == null)
{
@@ -150,7 +157,7 @@ public static async Task> ToListAsync(
}
var list = initialCapacity <= 0 ? new List() : new List(initialCapacity);
- var enumerator = result.GetAsyncEnumerator();
+ var enumerator = result.GetAsyncEnumerator(cancellationToken);
await using (enumerator.ConfigureAwait(false))
{
while (await enumerator.MoveNextAsync().ConfigureAwait(false))
@@ -166,17 +173,19 @@ public static async Task> ToListAsync(
/// Read each record in the result stream and apply the operation on each record.
/// The result stream.
/// The operation is carried out on each record.
+ /// A cancellation token that can be used to cancel the asynchronous operation.
/// The result summary after all records have been processed.
public static async Task ForEachAsync(
this IResultCursor result,
- Action operation)
+ Action operation,
+ CancellationToken cancellationToken = default)
{
if (result == null)
{
throw new ArgumentNullException(nameof(result));
}
- var enumerator = result.GetAsyncEnumerator();
+ var enumerator = result.GetAsyncEnumerator(cancellationToken);
await using (enumerator.ConfigureAwait(false))
{
while (await enumerator.MoveNextAsync().ConfigureAwait(false))