package funmow func EventBuffer(inbound chan PlayerEvent) chan PlayerEvent { queue := make([]*PlayerEvent, 0) inboundBuffer := make(chan PlayerEvent) go func() { running := true bufferLoop: for running { if len(queue) == 0 { select { case newEvent, ok := <-inbound: if !ok { break bufferLoop } queue = append(queue, &newEvent) } } else { event := queue[0] select { case newEvent, ok := <-inbound: if !ok { break bufferLoop } queue = append(queue, &newEvent) case inboundBuffer <- *event: queue = queue[1:] } } } close(inboundBuffer) }() return inboundBuffer }