@@ -121,15 +121,13 @@ open class PostBox<Value>: EventStream<Value>
121121#endif
122122
123123 let requested = self . requested
124- if requested <= 0 && CAtomicsLoad ( final, . relaxed) == nil { return }
124+ let terminal = Node ( storage: CAtomicsLoad ( self . final, . relaxed) )
125+ if requested <= 0 && terminal == nil { return }
125126
126127 // try to dequeue the next event
127128 let head = self . head
128- let next = CAtomicsLoad ( head. next, . acquire)
129-
130- if requested <= 0 && CAtomicsLoad ( final, . relaxed) != next { return }
131-
132- if let node = Node ( storage: next)
129+ if let node = Node ( storage: CAtomicsLoad ( head. next, . acquire) ) ,
130+ requested > 0 || node == terminal
133131 {
134132 let event = node. move ( )
135133 self . head = node
@@ -140,9 +138,9 @@ open class PostBox<Value>: EventStream<Value>
140138 return
141139 }
142140
143- // Either the queue is empty, or processing is blocked.
144- // Either way , processing will resume once
145- // a node has been linked after the current `head`
141+ // The queue is empty, there is no request , or processing is blocked.
142+ // In any case , processing will resume once there is either
143+ // a node linked after the current `head` or a non-zero request.
146144 }
147145
148146 open override func processAdditionalRequest( _ additional: Int64 )
0 commit comments