Source File
timeutil.go
Belonging Package
github.com/hibiken/asynq/internal/timeutil
// Copyright 2022 Kentaro Hibino. All rights reserved.// Use of this source code is governed by a MIT license// that can be found in the LICENSE file.// Package timeutil exports functions and types related to time and date.package timeutilimport ()// A Clock is an object that can tell you the current time.//// This interface allows decoupling code that uses time from the code that creates// a point in time. You can use this to your advantage by injecting Clocks into interfaces// rather than having implementations call time.Now() directly.//// Use RealClock() in production.// Use SimulatedClock() in test.type Clock interface {Now() time.Time}func () Clock { return &realTimeClock{} }type realTimeClock struct{}func ( *realTimeClock) () time.Time { return time.Now() }// A SimulatedClock is a concrete Clock implementation that doesn't "tick" on its own.// Time is advanced by explicit call to the AdvanceTime() or SetTime() functions.// This object is concurrency safe.type SimulatedClock struct {mu sync.Mutext time.Time // guarded by mu}func ( time.Time) *SimulatedClock {return &SimulatedClock{t: }}func ( *SimulatedClock) () time.Time {.mu.Lock()defer .mu.Unlock()return .t}func ( *SimulatedClock) ( time.Time) {.mu.Lock()defer .mu.Unlock().t =}func ( *SimulatedClock) ( time.Duration) {.mu.Lock()defer .mu.Unlock().t = .t.Add()}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |