Highly-opinionated (ex-bullshit-free) MTPROTO proxy for Telegram. If you use v1.0 or upgrade broke you proxy, please read the chapter Version 2
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

updater.go 556B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package dc
  2. import (
  3. "context"
  4. "time"
  5. )
  6. type updater struct {
  7. logger Logger
  8. period time.Duration
  9. }
  10. func (u updater) run(ctx context.Context, callback func() error) {
  11. ticker := time.NewTicker(u.period)
  12. defer func() {
  13. ticker.Stop()
  14. select {
  15. case <-ticker.C:
  16. default:
  17. }
  18. }()
  19. for {
  20. u.logger.Info("start update")
  21. if err := callback(); err != nil {
  22. u.logger.WarningError("cannot update: %w", err)
  23. }
  24. u.logger.Info("updated")
  25. select {
  26. case <-ctx.Done():
  27. u.logger.Info("stop updating")
  28. return
  29. case <-ticker.C:
  30. }
  31. }
  32. }