public async Task ForeachFiltersAsync(Func <FilterModel, Task> todo, Height fromHeight, CancellationToken cancel = default) { using (await IndexLock.LockAsync(cancel).ConfigureAwait(false)) using (await MatureIndexAsyncLock.LockAsync(cancel).ConfigureAwait(false)) { var firstImmatureHeight = ImmatureFilters.FirstOrDefault()?.Header?.Height; if (!firstImmatureHeight.HasValue || firstImmatureHeight.Value > fromHeight) { if (MatureIndexFileManager.Exists()) { uint height = StartingHeight; using var sr = MatureIndexFileManager.OpenText(); if (!sr.EndOfStream) { var lineTask = sr.ReadLineAsync(); Task tTask = Task.CompletedTask; string?line = null; while (lineTask is { })
public async Task ForeachFiltersAsync(Func <FilterModel, Task> todo, Height fromHeight) { using (await MatureIndexFileManager.Mutex.LockAsync()) using (await IndexLock.LockAsync()) { var firstImmatureHeight = ImmatureFilters.FirstOrDefault()?.BlockHeight; if (!firstImmatureHeight.HasValue || firstImmatureHeight.Value > fromHeight) { if (MatureIndexFileManager.Exists()) { Height height = StartingHeight; using (var sr = MatureIndexFileManager.OpenText(16384)) { while (!sr.EndOfStream) { var line = await sr.ReadLineAsync(); if (firstImmatureHeight == height) { break; // Let's use our the immature filters from here on. The content is the same, just someone else modified the file. } if (height < fromHeight.Value) { height++; continue; } var filter = FilterModel.FromHeightlessLine(line, height); await todo(filter); height++; } } } } foreach (FilterModel filter in ImmatureFilters) { await todo(filter); } } }
public async Task ForeachFiltersAsync(Func <FilterModel, Task> todo, Height fromHeight, CancellationToken cancel = default) { using (await MatureIndexFileManager.Mutex.LockAsync(cancel).ConfigureAwait(false)) using (await IndexLock.LockAsync(cancel).ConfigureAwait(false)) { var firstImmatureHeight = ImmatureFilters.FirstOrDefault()?.Header?.Height; if (!firstImmatureHeight.HasValue || firstImmatureHeight.Value > fromHeight) { if (MatureIndexFileManager.Exists()) { uint height = StartingHeight; using var sr = MatureIndexFileManager.OpenText(); if (!sr.EndOfStream) { var lineTask = sr.ReadLineAsync(); Task tTask = Task.CompletedTask; string line = null; while (lineTask != null) { if (firstImmatureHeight == height) { break; // Let's use our the immature filters from here on. The content is the same, just someone else modified the file. } if (line is null) { line = await lineTask.ConfigureAwait(false); } lineTask = sr.EndOfStream ? null : sr.ReadLineAsync(); if (height < fromHeight.Value) { height++; line = null; continue; } var filter = FilterModel.FromLine(line); await tTask.ConfigureAwait(false); tTask = todo(filter); height++; line = null; } await tTask.ConfigureAwait(false); } while (!sr.EndOfStream) { var line = await sr.ReadLineAsync().ConfigureAwait(false); if (firstImmatureHeight == height) { break; // Let's use our the immature filters from here on. The content is the same, just someone else modified the file. } if (height < fromHeight.Value) { height++; continue; } var filter = FilterModel.FromLine(line); await todo(filter).ConfigureAwait(false); height++; } } } foreach (FilterModel filter in ImmatureFilters) { await todo(filter).ConfigureAwait(false); } } }