Maint: make all set status context aware

This commit is contained in:
Quentin McGaw (desktop)
2021-07-16 00:49:59 +00:00
parent 6bbb7c8f7d
commit 0ed738cd61
16 changed files with 146 additions and 57 deletions

View File

@@ -69,9 +69,15 @@ func (l *looper) SetStatus(ctx context.Context, status models.LoopStatus) (
l.state.status = constants.Stopping
l.state.statusMu.Unlock()
l.stop <- struct{}{}
<-l.stopped
newStatus := constants.Stopping // for canceled context
select {
case <-ctx.Done():
case <-l.stopped:
newStatus = constants.Stopped
}
l.state.statusMu.Lock()
l.state.status = constants.Stopped
l.state.status = newStatus
return status.String(), nil
default:
return "", fmt.Errorf("%w: %s: it can only be one of: %s, %s",