Debian Codegraph @

pkg/util/flowcontrol/fairqueuing/eventclock/real.go

raw
1 /*
2 Copyright 2021 The Kubernetes Authors.
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 package eventclock
18
19 import (
20 "time"
21
22 "k8s.io/utils/clock"
23 )
24
25 // RealEventClock fires event on real world time
26 type Real struct {
27 clock.RealClock
28 }
29
30 var _ Interface = Real{}
31
32 // EventAfterDuration schedules an EventFunc
33 func (Real) EventAfterDuration(f EventFunc, d time.Duration) {
34 ch := time.After(d)
35 go func() {
36 t := <-ch
37 f(t)
38 }()
39 }
40
41 // EventAfterTime schedules an EventFunc
42 func (r Real) EventAfterTime(f EventFunc, t time.Time) {
43 r.EventAfterDuration(f, time.Until(t))
44 }