k8s.io/apiserver@v0.31.1/pkg/util/flowcontrol/fairqueuing/eventclock/interface.go (about) 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 baseclock "k8s.io/utils/clock" 23 ) 24 25 // EventFunc does some work that needs to be done at or after the 26 // given time. 27 type EventFunc func(time.Time) 28 29 // EventClock is an active clock abstraction for use in code that is 30 // testable with a fake clock that itself determines how time may be 31 // advanced. The timing paradigm is invoking EventFuncs rather than 32 // synchronizing through channels, so that the fake clock has a handle 33 // on when associated activity is done. 34 type Interface interface { 35 baseclock.PassiveClock 36 37 // Sleep returns after the given duration (or more). 38 Sleep(d time.Duration) 39 40 // EventAfterDuration invokes the given EventFunc after the given duration (or more), 41 // passing the time when the invocation was launched. 42 EventAfterDuration(f EventFunc, d time.Duration) 43 44 // EventAfterTime invokes the given EventFunc at the given time or later, 45 // passing the time when the invocation was launched. 46 EventAfterTime(f EventFunc, t time.Time) 47 }