mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 16:14:02 +03:00
Add doppel and tls packages
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package doppel
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Clock struct {
|
||||
stats *Stats
|
||||
tick chan struct{}
|
||||
}
|
||||
|
||||
func (c Clock) Start(ctx context.Context) {
|
||||
tickTock := time.NewTimer(c.stats.Delay())
|
||||
defer func() {
|
||||
tickTock.Stop()
|
||||
select {
|
||||
case <-tickTock.C:
|
||||
default:
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-tickTock.C:
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case c.tick <- struct{}{}:
|
||||
}
|
||||
tickTock.Reset(c.stats.Delay())
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user