agent/dockerclient/dockerapi/docker_events_buffer.go
func (buffer *InfiniteBuffer) Consume(in chan<- *events.Message) {
	for {
		buffer.lock.Lock()

		if len(buffer.events) == 0 {
			// Mark the buffer as empty and start waiting for events
			buffer.empty = true
			buffer.waitForEvent.Add(1)
			buffer.lock.Unlock()
			buffer.waitForEvent.Wait()
		} else {
			event := buffer.events[0]
			buffer.events = buffer.events[1:]
			buffer.lock.Unlock()

			// Send event to the buffer listener
			in <- event
		}
	}
}
func (buffer *InfiniteBuffer) Consume(in chan<- *events.Message) {
	for {
		buffer.lock.Lock()

		if len(buffer.events) == 0 {
			// Mark the buffer as empty and start waiting for events
			buffer.empty = true
			buffer.waitForEvent.Add(1)
			buffer.lock.Unlock()
			buffer.waitForEvent.Wait()
		} else {
			event := buffer.events[0]
			buffer.events = buffer.events[1:]
			buffer.lock.Unlock()

			// Send event to the buffer listener
			in <- event
		}
	}
}
func ( buffer * InfiniteBuffer ) Consume ( in chan <- * events . Message ) { for { buffer . lock . Lock ( ) if len ( buffer . events ) == 0 { // Mark the buffer as empty and start waiting for events buffer . empty = true buffer . waitForEvent . Add ( 1 ) buffer . lock . Unlock ( ) buffer . waitForEvent . Wait ( ) } else { event := buffer . events [ 0 ] buffer . events = buffer . events [ 1 : ] buffer . lock . Unlock ( ) // Send event to the buffer listener in <- event } } }
// Consume reads the buffer and write to a listener channel
Consume reads the buffer and write to a listener channel