summaryrefslogtreecommitdiff
path: root/timeoutat/timeoutat.go
diff options
context:
space:
mode:
authorWill Hawkins <[email protected]>2021-12-13 21:44:50 -0500
committerWill Hawkins <[email protected]>2021-12-13 21:44:50 -0500
commit4c9a70fe1c7e7596eebaf475cf78596eee614c7e (patch)
treed3f5c396f0e0daaab1b24b6238bf0730692e0b75 /timeoutat/timeoutat.go
parent339a162877a78641a45338983de2192353fe7a5a (diff)
Intermediate check-in commit. Adding functionality and refactoring.
Diffstat (limited to 'timeoutat/timeoutat.go')
-rw-r--r--timeoutat/timeoutat.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/timeoutat/timeoutat.go b/timeoutat/timeoutat.go
new file mode 100644
index 0000000..e77804e
--- /dev/null
+++ b/timeoutat/timeoutat.go
@@ -0,0 +1,30 @@
+package timeoutat
+
+import (
+ "context"
+ "fmt"
+ "time"
+)
+
+type TimeoutAt struct {
+ when time.Time
+ response chan interface{}
+}
+
+func NewTimeoutAt(ctx context.Context, when time.Time, response chan interface{}) *TimeoutAt {
+ timeoutAt := &TimeoutAt{when: when, response: response}
+ timeoutAt.start(ctx)
+ return timeoutAt
+}
+
+func (ta *TimeoutAt) start(ctx context.Context) {
+ go func() {
+ fmt.Printf("Timeout expected to end at %v\n", ta.when)
+ select {
+ case <-time.After(ta.when.Sub(time.Now())):
+ case <-ctx.Done():
+ }
+ ta.response <- struct{}{}
+ fmt.Printf("Timeout ended at %v\n", time.Now())
+ }()
+}