Skip to content

Commit b4c8f11

Browse files
committed
remove unnecessary queue len check in unblock
1 parent 9128757 commit b4c8f11

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

limiter/lifo_blocking.go

+17-21
Original file line numberDiff line numberDiff line change
@@ -119,33 +119,29 @@ func (l *LifoBlockingListener) unblock() {
119119
l.limiter.mu.Lock()
120120
defer l.limiter.mu.Unlock()
121121

122-
if l.limiter.backlog.len() > 0 {
122+
evict, nextEvent := l.limiter.backlog.peek()
123123

124-
evict, nextEvent := l.limiter.backlog.peek()
125-
126-
// Last element expired between us checking the
127-
// queue length and invoking peek
128-
if nextEvent == nil {
129-
return
130-
}
124+
// The queue is empty
125+
if nextEvent == nil {
126+
return
127+
}
131128

132-
listener, ok := l.limiter.delegate.Acquire(nextEvent.ctx)
129+
listener, ok := l.limiter.delegate.Acquire(nextEvent.ctx)
133130

134-
if ok && listener != nil {
135-
// We successfully acquired a listener from the
136-
// delegate. Now we can evict the element from
137-
// the queue
138-
evict()
131+
if ok && listener != nil {
132+
// We successfully acquired a listener from the
133+
// delegate. Now we can evict the element from
134+
// the queue
135+
evict()
139136

140-
// If the listener is not accepted due to subtle timings
141-
// between setListener being invoked and the element
142-
// expiration elapsing we need to be sure to release it.
143-
if accepted := nextEvent.setListener(listener); !accepted {
144-
listener.OnIgnore()
145-
}
137+
// If the listener is not accepted due to subtle timings
138+
// between setListener being invoked and the element
139+
// expiration elapsing we need to be sure to release it.
140+
if accepted := nextEvent.setListener(listener); !accepted {
141+
listener.OnIgnore()
146142
}
147-
// otherwise: still can't acquire the limit. unblock will be called again next time the limit is released.
148143
}
144+
// otherwise: still can't acquire the limit. unblock will be called again next time the limit is released.
149145
}
150146

151147
// OnDropped is called to indicate the request failed and was dropped due to being rejected by an external limit or

0 commit comments

Comments
 (0)