Read implements the io.Reader interface.
(p []byte)
| 88 | |
| 89 | // Read implements the io.Reader interface. |
| 90 | func (r *BGReader) Read(p []byte) (int, error) { |
| 91 | r.cond.L.Lock() |
| 92 | defer r.cond.L.Unlock() |
| 93 | |
| 94 | if len(r.readResults) > 0 { |
| 95 | return r.readFromReadResults(p) |
| 96 | } |
| 97 | |
| 98 | // There are no unread background read results and the background reader is stopped. |
| 99 | if r.status == StatusStopped { |
| 100 | return r.r.Read(p) |
| 101 | } |
| 102 | |
| 103 | // Wait for results from the background reader |
| 104 | for len(r.readResults) == 0 { |
| 105 | r.cond.Wait() |
| 106 | } |
| 107 | return r.readFromReadResults(p) |
| 108 | } |
| 109 | |
| 110 | // readBackgroundResults reads a result previously read by the background reader. r.cond.L must be held. |
| 111 | func (r *BGReader) readFromReadResults(p []byte) (int, error) { |
no test coverage detected