blob: 74a3b7082242a2b699b8c5fa919808d28248ab08 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package timeoutat
import (
"context"
"fmt"
"time"
)
func TimeoutAt(ctx context.Context, when time.Time, debug bool) (response chan interface{}) {
response = make(chan interface{})
go func(ctx context.Context) {
go func() {
if debug {
fmt.Printf("Timeout expected to end at %v\n", when)
}
select {
case <-time.After(when.Sub(time.Now())):
case <-ctx.Done():
}
response <- struct{}{}
if debug {
fmt.Printf("Timeout ended at %v\n", time.Now())
}
}()
}(ctx)
return
}
|