@@ -119,33 +119,29 @@ func (l *LifoBlockingListener) unblock() {
119
119
l .limiter .mu .Lock ()
120
120
defer l .limiter .mu .Unlock ()
121
121
122
- if l .limiter .backlog .len () > 0 {
122
+ evict , nextEvent := l .limiter .backlog .peek ()
123
123
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
+ }
131
128
132
- listener , ok := l .limiter .delegate .Acquire (nextEvent .ctx )
129
+ listener , ok := l .limiter .delegate .Acquire (nextEvent .ctx )
133
130
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 ()
139
136
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 ()
146
142
}
147
- // otherwise: still can't acquire the limit. unblock will be called again next time the limit is released.
148
143
}
144
+ // otherwise: still can't acquire the limit. unblock will be called again next time the limit is released.
149
145
}
150
146
151
147
// OnDropped is called to indicate the request failed and was dropped due to being rejected by an external limit or
0 commit comments