public bool ReadChunks() { var readCount = 0; bool BufferIsFull() => readCount >= ApplicationConstants.BufferSlots; while (_reader.HasMore && !BufferIsFull() && _readSlotsSemaphore.Wait(TimeSpan.Zero)) { var chunk = _reader.ReadChunk(); readCount++; _onRead(chunk); } var isCompleted = !_reader.HasMore; if (!isCompleted) { _ioBoundQueue.Enqueue(new Function { Name = nameof(ReadChunks), Payload = _readChunksDelegate }); } return(isCompleted); }
public void Process(OrderedChunk chunk) { RentedArray <byte> processedData = _gzipProcessor.GetProcessedData(chunk); chunk.RentedData.Dispose(); var orderedChunk = new OrderedChunk { RentedData = processedData, Order = chunk.Order }; var writingFunction = new Function(nameof(IChunkedWriter.WriteOrStoreChunk), () => _chunkedWriter.WriteOrStoreChunk(orderedChunk)); _ioBoundQueue.Enqueue(writingFunction); _readSlotsSemaphore.Release(); }