Files
sablier/app/sessions/groups_watcher.go
Alexis Couvreur 72ea3b3645 refactor(provider): pass context.Context down to all operations
This means that with more work, a canceled request would cancel to underlying request.
2023-09-15 01:03:41 +02:00

28 lines
561 B
Go

package sessions
import (
"context"
"time"
"github.com/acouvreur/sablier/app/providers"
log "github.com/sirupsen/logrus"
)
// watchGroups watches indefinitely for new groups
func watchGroups(ctx context.Context, provider providers.Provider, frequency time.Duration, send chan<- map[string][]string) {
ticker := time.NewTicker(frequency)
for {
select {
case <-ctx.Done():
return
case <-ticker.C:
groups, err := provider.GetGroups(ctx)
if err != nil {
log.Warn("could not get groups", err)
} else {
send <- groups
}
}
}
}