Close closes the AsyncBuffer and releases all resources. It is idempotent.
()
| 197 | |
| 198 | // Close closes the AsyncBuffer and releases all resources. It is idempotent. |
| 199 | func (ab *AsyncBuffer) Close() error { |
| 200 | ab.mu.Lock() |
| 201 | defer ab.mu.Unlock() |
| 202 | |
| 203 | // If the reader is already closed, we return immediately error or nil |
| 204 | if ab.closed.Load() { |
| 205 | return nil |
| 206 | } |
| 207 | |
| 208 | ab.closed.Store(true) |
| 209 | |
| 210 | // Return all chunks to the pool |
| 211 | for _, chunk := range ab.chunks { |
| 212 | chunkPool.Put(chunk) |
| 213 | } |
| 214 | |
| 215 | // Release the paused latch so that no goroutines are waiting for it |
| 216 | ab.paused.Release() |
| 217 | |
| 218 | // Finish downloading |
| 219 | ab.callFinishFn() |
| 220 | |
| 221 | return nil |
| 222 | } |
| 223 | |
| 224 | // Reader returns an io.ReadSeeker+io.ReaderAt that can be used to read actual data from the AsyncBuffer |
| 225 | func (ab *AsyncBuffer) Reader() *Reader { |
no test coverage detected