Exemple #1
0
 async ValueTask <TResult> IAuditTrail <IRaftLogEntry> .ReadAsync <TReader, TResult>(TReader reader, long startIndex, CancellationToken token)
 {
     if (startIndex < 0L)
     {
         throw new ArgumentOutOfRangeException(nameof(startIndex));
     }
     using (await syncRoot.AcquireReadLockAsync(token).ConfigureAwait(false))
         return(await reader.ReadAsync <IRaftLogEntry, LogEntryList>(new LogEntryList(log, startIndex, GetLastIndex(false)), null, token).ConfigureAwait(false));
 }
 /// <summary>
 /// Reads the range of the log entries from this storage.
 /// </summary>
 /// <typeparam name="TResult">The type of the result.</typeparam>
 /// <param name="reader">The reader over log entries.</param>
 /// <param name="startIndex">The index of the first log entry to retrieve.</param>
 /// <param name="endIndex">The index of the last log entry to retrieve, inclusive.</param>
 /// <param name="token">The token that can be used to cancel the operation.</param>
 /// <returns>The result of the transformation applied to the range of the log entries.</returns>
 public async ValueTask <TResult> ReadAsync <TResult>(LogEntryConsumer <IRaftLogEntry, TResult> reader, long startIndex, long endIndex, CancellationToken token)
 {
     if (startIndex < 0L)
     {
         throw new ArgumentOutOfRangeException(nameof(startIndex));
     }
     if (endIndex < 0L)
     {
         throw new ArgumentOutOfRangeException(nameof(endIndex));
     }
     if (endIndex < startIndex)
     {
         return(await reader.ReadAsync <EmptyLogEntry, EmptyLogEntry[]>(Array.Empty <EmptyLogEntry>(), null, token).ConfigureAwait(false));
     }
     using (await syncRoot.AcquireReadLockAsync(token).ConfigureAwait(false))
         return(await ReadCoreAsync(reader, startIndex, endIndex, token).ConfigureAwait(false));
 }