Wait waits for the reader to finish reading all data and returns the total length of the data read.
()
| 152 | // Wait waits for the reader to finish reading all data and returns |
| 153 | // the total length of the data read. |
| 154 | func (ab *AsyncBuffer) Wait() (int, error) { |
| 155 | // Wait ends till the end of the stream: unpause the reader |
| 156 | ab.paused.Release() |
| 157 | |
| 158 | // Get initial cursor before first check |
| 159 | cursor := ab.chunkCond.Cursor() |
| 160 | |
| 161 | for { |
| 162 | // We can not read data from the closed reader |
| 163 | if err := ab.closedError(); err != nil { |
| 164 | return 0, err |
| 165 | } |
| 166 | |
| 167 | // In case the reader is finished reading, we can return immediately |
| 168 | if ab.finished.Load() { |
| 169 | return int(ab.bytesRead.Load()), ab.Error() |
| 170 | } |
| 171 | |
| 172 | // Lock until the next chunk is ready |
| 173 | cursor = ab.chunkCond.Wait(cursor) |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | // ReleaseThreshold releases the pause, allowing the buffer to immediately |
| 178 | // read data beyond the pause threshold. |
no test coverage detected