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
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

clock.go 463B

1234567891011121314151617181920212223242526272829303132333435
  1. package doppel
  2. import (
  3. "context"
  4. "time"
  5. )
  6. type Clock struct {
  7. stats *Stats
  8. tick chan struct{}
  9. }
  10. func (c Clock) Start(ctx context.Context) {
  11. tickTock := time.NewTimer(c.stats.Delay())
  12. defer func() {
  13. tickTock.Stop()
  14. select {
  15. case <-tickTock.C:
  16. default:
  17. }
  18. }()
  19. for {
  20. select {
  21. case <-ctx.Done():
  22. return
  23. case <-tickTock.C:
  24. select {
  25. case <-ctx.Done():
  26. case c.tick <- struct{}{}:
  27. }
  28. tickTock.Reset(c.stats.Delay())
  29. }
  30. }
  31. }