Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Clock ¶
type Clock interface { Now() time.Time Since(time.Time) time.Duration Sleep(time.Duration) WithTimeout(context.Context, time.Duration) (context.Context, context.CancelFunc) }
Clock defines how Fx accesses time. We keep the interface pretty minimal.
var System Clock = systemClock{}
System is the default implementation of Clock based on real time.
type Mock ¶ added in v1.21.0
type Mock struct {
// contains filtered or unexported fields
}
Mock is a fake source of time. It implements standard time operations, but allows the user to control the passage of time.
Use the [Add] method to progress time.
func NewMock ¶ added in v1.21.0
func NewMock() *Mock
NewMock builds a new mock clock using the current actual time as the initial time.
func (*Mock) Add ¶ added in v1.21.0
Add progresses time by the given duration. Other operations waiting for the time to advance will be resolved if they are within range.
Side effects of operations waiting for the time to advance will take effect on a best-effort basis. Avoid racing with operations that have side effects.
Panics if the duration is negative.
func (*Mock) AwaitScheduled ¶ added in v1.21.0
AwaitScheduled blocks until there are at least N operations scheduled for the future.
func (*Mock) Since ¶ added in v1.21.0
Since reports the time elapsed since t. This is short for Now().Sub(t).
func (*Mock) Sleep ¶ added in v1.21.0
Sleep pauses the current goroutine for the given duration.
With the mock clock, this will freeze until the clock is advanced with [Add] past the deadline.
func (*Mock) WithTimeout ¶ added in v1.21.0
func (c *Mock) WithTimeout(ctx context.Context, d time.Duration) (context.Context, context.CancelFunc)
WithTimeout returns a new context with a deadline of now + d.
When the deadline is passed, the returned context's Done channel is closed and the context's Err method returns context.DeadlineExceeded. If the cancel function is called before the deadline is passed, the context's Err method returns context.Canceled.