Skip to content

Commit

Permalink
remove explicit semaphore
Browse files Browse the repository at this point in the history
  • Loading branch information
Daisuke Maki committed Sep 29, 2024
1 parent 2edd851 commit 01ce94a
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions proxysink/proxysink.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ type Backend[T any] interface {
// Proxy is used to send values through a channel. This is used to
// serialize calls to underlying sinks.
type Proxy[T any] struct {
mu *sync.RWMutex
mu *sync.Mutex
ch chan T
cond *sync.Cond
pending []T
backend Backend[T]
}

func New[T any](b Backend[T]) *Proxy[T] {
mu := &sync.RWMutex{}
mu := &sync.Mutex{}
return &Proxy[T]{
ch: make(chan T, 1),
mu: mu,
Expand Down Expand Up @@ -91,8 +91,6 @@ func (p *Proxy[T]) flushloop(ctx context.Context) {
}

func (p *Proxy[T]) Put(ctx context.Context, v T) {
p.mu.RLock()
defer p.mu.RUnlock()
select {
case <-ctx.Done():
return
Expand All @@ -102,7 +100,5 @@ func (p *Proxy[T]) Put(ctx context.Context, v T) {
}

func (p *Proxy[T]) Close() {
p.mu.Lock()
close(p.ch)
p.mu.Unlock()
}

0 comments on commit 01ce94a

Please sign in to comment.