MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / WaitFor

Method WaitFor

asyncbuffer/buffer.go:129–150  ·  view source on GitHub ↗

WaitFor waits for the data to be ready at the given offset. nil means ok. It guarantees that the chunk at the given offset is ready to be read.

(off int64)

Source from the content-addressed store, hash-verified

127// WaitFor waits for the data to be ready at the given offset. nil means ok.
128// It guarantees that the chunk at the given offset is ready to be read.
129func (ab *AsyncBuffer) WaitFor(off int64) error {
130 // Get initial cursor before first check
131 cursor := ab.chunkCond.Cursor()
132
133 // In case we are trying to read data which would potentially hit the pause threshold,
134 // we need to unpause the reader ASAP.
135 if off >= PauseThreshold {
136 ab.paused.Release()
137 }
138
139 for {
140 ok, err := ab.offsetAvailable(off)
141 if ok || err != nil {
142 return err
143 }
144
145 // Wait for a Tick() to occur after our cursor.
146 // If a Tick() happened between offsetAvailable() and here, Wait() returns immediately.
147 // This prevents the deadlock where we miss a signal.
148 cursor = ab.chunkCond.Wait(cursor)
149 }
150}
151
152// Wait waits for the reader to finish reading all data and returns
153// the total length of the data read.

Callers 2

ReadAtMethod · 0.95
TestAsyncBufferReadAsyncFunction · 0.80

Calls 4

offsetAvailableMethod · 0.95
CursorMethod · 0.80
ReleaseMethod · 0.80
WaitMethod · 0.45

Tested by 1

TestAsyncBufferReadAsyncFunction · 0.64