Maint: move OpenVPN streams processing to config package

This commit is contained in:
Quentin McGaw (desktop)
2021-08-18 21:16:28 +00:00
parent a0cb6fabfd
commit 0027a76c49
8 changed files with 136 additions and 73 deletions

View File

@@ -8,6 +8,28 @@ import (
"github.com/qdm12/gluetun/internal/models"
)
// waitForError waits 100ms for an error in the waitError channel.
func (l *Loop) waitForError(ctx context.Context,
waitError chan error) (err error) {
const waitDurationForError = 100 * time.Millisecond
timer := time.NewTimer(waitDurationForError)
select {
case <-ctx.Done():
if !timer.Stop() {
<-timer.C
}
return ctx.Err()
case <-timer.C:
return nil
case err := <-waitError:
close(waitError)
if !timer.Stop() {
<-timer.C
}
return err
}
}
func (l *Loop) crashed(ctx context.Context, err error) {
l.signalOrSetStatus(constants.Crashed)
l.logAndWait(ctx, err)