addChunk adds a new chunk to the AsyncBuffer, increments bytesRead and signals that a chunk is ready
(chunk *byteChunk)
| 323 | // addChunk adds a new chunk to the AsyncBuffer, increments bytesRead |
| 324 | // and signals that a chunk is ready |
| 325 | func (ab *AsyncBuffer) addChunk(chunk *byteChunk) { |
| 326 | ab.mu.Lock() |
| 327 | defer ab.mu.Unlock() |
| 328 | |
| 329 | if ab.closed.Load() { |
| 330 | // If the reader is closed, we return the chunk to the pool |
| 331 | chunkPool.Put(chunk) |
| 332 | return |
| 333 | } |
| 334 | |
| 335 | // Store the chunk, increase chunk size, increase length of the data read |
| 336 | ab.chunks = append(ab.chunks, chunk) |
| 337 | ab.bytesRead.Add(int64(len(chunk.data))) |
| 338 | |
| 339 | ab.chunkCond.Tick() |
| 340 | } |
| 341 | |
| 342 | // readChunks reads data from the upstream reader in background and stores them in the pool |
| 343 | func (ab *AsyncBuffer) readChunks() { |
no test coverage detected