Closed Kugelschieber closed 2 years ago
Should make sure it's not full before adding more sessions. The buffer can be expanded indefinitely, in theory.
func (tracker *Tracker) aggregateSessions(ctx context.Context) { sessions := make([]Session, 0, tracker.workerBufferSize*2) timer := time.NewTimer(tracker.workerTimeout) defer timer.Stop() for { timer.Reset(tracker.workerTimeout) select { case session := <-tracker.sessions: if session.Cancel != nil { sessions = append(sessions, *session.Cancel) } sessions = append(sessions, session.State) if len(sessions) >= tracker.workerBufferSize*2 { tracker.saveSessions(sessions) sessions = sessions[:0] } case <-timer.C: tracker.saveSessions(sessions) sessions = sessions[:0] case <-ctx.Done(): tracker.saveSessions(sessions) tracker.workerDone <- true return } } }
Should make sure it's not full before adding more sessions. The buffer can be expanded indefinitely, in theory.