Class AbstractCursor<T>
- Namespace
- DataStax.AstraDB.DataApi.Core.Enumeration
- Assembly
- DataStax.AstraDB.DataApi.dll
Abstract base class for cursors that iterate over query results in a streaming manner.
This cursor provides state management, buffering, and both synchronous and asynchronous enumeration capabilities. Results are fetched in batches from the underlying API and buffered for efficient iteration.
public abstract class AbstractCursor<T> : IDisposable, IEnumerable<T>, IEnumerable, IAsyncEnumerable<T>
Type Parameters
TThe type of the items or rows in the cursor.
- Inheritance
-
AbstractCursor<T>
- Implements
-
IEnumerable<T>
- Derived
- Inherited Members
Properties
Consumed
Gets the total number of items consumed from the cursor so far.
public int Consumed { get; protected set; }
Property Value
State
Gets the current state of the cursor.
public CursorState State { get; protected set; }
Property Value
_buffer
Gets the internal buffer containing fetched results.
protected abstract List<T> _buffer { get; }
Property Value
- List<T>
Methods
Buffered()
Returns the number of items currently buffered in memory.
public int Buffered()
Returns
- int
The count of buffered items.
ConsumeBuffer(int)
Consumes and returns items from the buffer.
public IReadOnlyList<T> ConsumeBuffer(int max = 0)
Parameters
maxintThe maximum number of items to consume. If 0 or omitted, consumes all buffered items.
Returns
- IReadOnlyList<T>
A read-only list of consumed items.
Dispose()
Releases all resources used by the cursor and sets its state to Closed.
public virtual void Dispose()
FetchMoreAsync(CancellationToken, bool)
Fetches the next page of results from the underlying data source.
protected abstract Task<bool> FetchMoreAsync(CancellationToken cancellationToken, bool runSynchronously)
Parameters
cancellationTokenCancellationTokenA cancellation token to cancel the operation.
runSynchronouslyboolWhether to run the operation synchronously.
Returns
GetAsyncEnumerator(CancellationToken)
Returns an async enumerator to iterate over all items in the cursor.
public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenAn optional cancellation token to cancel the operation.
Returns
- IAsyncEnumerator<T>
An async enumerator for the cursor.
Exceptions
- CursorException
Thrown when attempting to iterate over a closed cursor.
GetEnumerator()
Returns an enumerator to iterate over all items in the cursor.
public IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
An enumerator for the cursor.
Exceptions
- CursorException
Thrown when attempting to iterate over a closed cursor.
HasNext()
Synchronously checks if there are more items available without consuming them.
public bool HasNext()
Returns
- bool
True if there are more items available, false otherwise.
Remarks
The asynchronous version HasNextAsync(CancellationToken) is recommended to avoid potential deadlocks.
HasNextAsync(CancellationToken)
Asynchronously checks if there are more items available without consuming them.
public Task<bool> HasNextAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenAn optional cancellation token to cancel the operation.
Returns
MoveNext()
Synchronously moves to and returns the next item in the cursor.
public T MoveNext()
Returns
- T
The next item, or null if there are no more items.
Remarks
The asynchronous version MoveNextAsync(CancellationToken) is recommended to avoid potential deadlocks.
MoveNextAsync(CancellationToken)
Asynchronously moves to and returns the next item in the cursor.
public Task<T> MoveNextAsync(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenAn optional cancellation token to cancel the operation.
Returns
- Task<T>
The next item, or null if there are no more items.
MoveNextAsync(CancellationToken, bool, bool)
Internal method to move to the next item, with options to peek or consume.
protected Task<T> MoveNextAsync(CancellationToken cancellationToken, bool peek, bool runSynchronously)
Parameters
cancellationTokenCancellationTokenA cancellation token to cancel the operation.
peekboolIf true, returns the next item without consuming it.
runSynchronouslyboolWhether to run the operation synchronously.
Returns
- Task<T>
The next item, or null if there are no more items.
Rewind()
Resets the cursor to its initial state, allowing iteration to start over from the beginning.
public virtual void Rewind()
Remarks
This resets the consumed count and cursor state, but does not refetch data. The next iteration will start from the first page again.