agent/dockerclient/dockerapi/docker_events_buffer.go
func (buffer *InfiniteBuffer) StartListening(ctx context.Context, eventChan <-chan events.Message) {
	for {
		select {
		// If context is cancelled, drain remaining events and return
		case <-ctx.Done():
			for len(eventChan) > 0 {
				event := <-eventChan
				go buffer.CopyEvents(&event)
			}
			return
		case event := <-eventChan:
			go buffer.CopyEvents(&event)
		}
	}
}
func (buffer *InfiniteBuffer) StartListening(ctx context.Context, eventChan <-chan events.Message) {
	for {
		select {
		// If context is cancelled, drain remaining events and return
		case <-ctx.Done():
			for len(eventChan) > 0 {
				event := <-eventChan
				go buffer.CopyEvents(&event)
			}
			return
		case event := <-eventChan:
			go buffer.CopyEvents(&event)
		}
	}
}
func ( buffer * InfiniteBuffer ) StartListening ( ctx context . Context , eventChan <- chan events . Message ) { for { select { // If context is cancelled, drain remaining events and return case <- ctx . Done ( ) : for len ( eventChan ) > 0 { event := <- eventChan go buffer . CopyEvents ( & event ) } return case event := <- eventChan : go buffer . CopyEvents ( & event ) } } }
// StartListening starts reading from the input channel and writes to the buffer
// When context is cancelled, stop listening
StartListening starts reading from the input channel and writes to the buffer When context is cancelled stop listening