Files
imgproxy/asyncbuffer/latch.go
Victor Sokolov 0015e88447 IMG-13: pauseThreshold in AsyncBuffer + close behaviour (#1477)
* pauseThreshold in AsyncBuffer

* Additional close() condition

* io.ReadCloser in buffer

* ticker + fixes

* Minor fixes for asyncbuffer

* Renamed ticker to cond

* warn if close of upstream reader failed

* ticker -> chunkCond

* Fix io.EOF behaviour
2025-08-06 18:45:53 +02:00

27 lines
465 B
Go

package asyncbuffer
import (
"sync"
)
// Latch is once-releasing semaphore.
type Latch struct {
once sync.Once
done chan struct{}
}
// NewLatch creates a new Latch.
func NewLatch() *Latch {
return &Latch{done: make(chan struct{})}
}
// Release releases the latch, allowing all waiting goroutines to proceed.
func (g *Latch) Release() {
g.once.Do(func() { close(g.done) })
}
// Wait blocks until the latch is released.
func (g *Latch) Wait() {
<-g.done
}