AsyncBuffer is a wrapper around io.Reader that reads data in chunks in background and allows reading from synchronously.
| 58 | // AsyncBuffer is a wrapper around io.Reader that reads data in chunks |
| 59 | // in background and allows reading from synchronously. |
| 60 | type AsyncBuffer struct { |
| 61 | r io.ReadCloser // Upstream reader |
| 62 | dataLen int // Expected length of the data in r, <= 0 means unknown length |
| 63 | |
| 64 | chunks []*byteChunk // References to the chunks read from the upstream reader |
| 65 | mu sync.RWMutex // Mutex on chunks slice |
| 66 | |
| 67 | err atomic.Value // Error that occurred during reading |
| 68 | bytesRead atomic.Int64 // Total length of the data read |
| 69 | |
| 70 | finished atomic.Bool // Indicates that the buffer has finished reading |
| 71 | closed atomic.Bool // Indicates that the buffer was closed |
| 72 | |
| 73 | paused *Latch // Paused buffer does not read data beyond threshold |
| 74 | chunkCond *Cond // Ticker that signals when a new chunk is ready |
| 75 | |
| 76 | finishOnce sync.Once |
| 77 | finishFn []context.CancelFunc |
| 78 | } |
| 79 | |
| 80 | // New creates a new AsyncBuffer that reads from the given io.ReadCloser in background |
| 81 | // and closes it when finished. |
nothing calls this directly
no outgoing calls
no test coverage detected