Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
kardolus
GitHub Repository: kardolus/chatgpt-cli
Path: blob/main/agent/core/clock.go
3434 views
1
package core
2
3
import (
4
"context"
5
"time"
6
)
7
8
type Clock interface {
9
Now() time.Time
10
Sleep(ctx context.Context, d time.Duration) error
11
}
12
13
type RealClock struct{}
14
15
func NewRealClock() *RealClock { return &RealClock{} }
16
17
func (c *RealClock) Now() time.Time { return time.Now() }
18
19
func (c *RealClock) Sleep(ctx context.Context, d time.Duration) error {
20
t := time.NewTimer(d)
21
defer t.Stop()
22
23
select {
24
case <-ctx.Done():
25
return ctx.Err()
26
case <-t.C:
27
return nil
28
}
29
}
30
31