Method ForEachAsync
ForEachAsync<TDocument>(IAsyncCursorSource<TDocument>, Func<TDocument, Task>, CancellationToken)
Calls a delegate for each document returned by the cursor.
public static Task ForEachAsync<TDocument>(this IAsyncCursorSource<TDocument> source, Func<TDocument, Task> processor, CancellationToken cancellationToken = default)
Parameters
source
IAsyncCursorSource<TDocument>The source.
processor
Func<TDocument, Task>The processor.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task
A Task that completes when all the documents have been processed.
Type Parameters
TDocument
The type of the document.
ForEachAsync<TDocument>(IAsyncCursorSource<TDocument>, Func<TDocument, int, Task>, CancellationToken)
Calls a delegate for each document returned by the cursor.
public static Task ForEachAsync<TDocument>(this IAsyncCursorSource<TDocument> source, Func<TDocument, int, Task> processor, CancellationToken cancellationToken = default)
Parameters
source
IAsyncCursorSource<TDocument>The source.
processor
Func<TDocument, int, Task>The processor.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task
A Task that completes when all the documents have been processed.
Type Parameters
TDocument
The type of the document.
ForEachAsync<TDocument>(IAsyncCursorSource<TDocument>, Action<TDocument>, CancellationToken)
Calls a delegate for each document returned by the cursor.
public static Task ForEachAsync<TDocument>(this IAsyncCursorSource<TDocument> source, Action<TDocument> processor, CancellationToken cancellationToken = default)
Parameters
source
IAsyncCursorSource<TDocument>The source.
processor
Action<TDocument>The processor.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task
A Task that completes when all the documents have been processed.
Type Parameters
TDocument
The type of the document.
Remarks
If your delegate is going to take a long time to execute or is going to block consider using a different overload of ForEachAsync that uses a delegate that returns a Task instead.
ForEachAsync<TDocument>(IAsyncCursorSource<TDocument>, Action<TDocument, int>, CancellationToken)
Calls a delegate for each document returned by the cursor.
public static Task ForEachAsync<TDocument>(this IAsyncCursorSource<TDocument> source, Action<TDocument, int> processor, CancellationToken cancellationToken = default)
Parameters
source
IAsyncCursorSource<TDocument>The source.
processor
Action<TDocument, int>The processor.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task
A Task that completes when all the documents have been processed.
Type Parameters
TDocument
The type of the document.
Remarks
If your delegate is going to take a long time to execute or is going to block consider using a different overload of ForEachAsync that uses a delegate that returns a Task instead.