mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-09-01 16:01:55 +03:00
Add fetching of addresses from proxyGetConfig endpoint
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package dc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type updater struct {
|
||||
logger Logger
|
||||
period time.Duration
|
||||
}
|
||||
|
||||
func (u updater) run(ctx context.Context, callback func() error) {
|
||||
ticker := time.NewTicker(u.period)
|
||||
|
||||
defer func() {
|
||||
ticker.Stop()
|
||||
|
||||
select {
|
||||
case <-ticker.C:
|
||||
default:
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
u.logger.Info("start update")
|
||||
if err := callback(); err != nil {
|
||||
u.logger.WarningError("cannot update: %w", err)
|
||||
}
|
||||
u.logger.Info("updated")
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
u.logger.Info("stop updating")
|
||||
return
|
||||
case <-ticker.C:
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user