Pārlūkot izejas kodu

Release asyncbuffer pause after detectiong image type

DarthSim 3 mēneši atpakaļ
vecāks
revīzija
6a87fb2a94
2 mainītis faili ar 10 papildinājumiem un 0 dzēšanām
  1. 6 0
      asyncbuffer/buffer.go
  2. 4 0
      imagedata/factory.go

+ 6 - 0
asyncbuffer/buffer.go

@@ -309,6 +309,12 @@ func (ab *AsyncBuffer) Wait() (int, error) {
 	}
 }
 
+// ReleaseThreshold releases the pause, allowing the buffer to immediately
+// read data beyond the pause threshold.
+func (ab *AsyncBuffer) ReleaseThreshold() {
+	ab.paused.Release()
+}
+
 // Error returns the error that occurred during reading data in background.
 func (ab *AsyncBuffer) Error() error {
 	err := ab.err.Load()

+ 4 - 0
imagedata/factory.go

@@ -177,6 +177,10 @@ func (f *Factory) DownloadAsync(ctx context.Context, imageURL, desc string, opts
 		return nil, h, wrapDownloadError(err, desc)
 	}
 
+	// We successfully detected the image type, so we can release the pause
+	// and let the buffer read the rest of the data immediately.
+	b.ReleaseThreshold()
+
 	d := &imageDataAsyncBuffer{
 		b:      b,
 		format: format,