mirror of
https://github.com/imgproxy/imgproxy.git
synced 2025-10-11 04:32:29 +02:00
* 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
27 lines
465 B
Go
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
|
|
}
|