Package clock provides an abstraction for system time that enables testing of time-sensitive code. Where you'd use time.Now, instead use clk.Now where clk is an instance of Clock. When running your code in production, pass it a Clock given by clock.Default() and when you're running it in your tests, pass it an instance of Clock from NewFake(). When you do that, you can use FakeClock's Add and Set methods to control how time behaves in your tests. That makes the tests you'll write more reliable while also expanding the space of problems you can test. This code intentionally does not attempt to provide an abstraction over time.Ticker and time.Timer because Go does not have the runtime or API hooks available to do so reliably. See https://github.com/golang/go/issues/8869
Package clock 可以模拟 time 和 context 标准库的部分行为。 All methods are safe for concurrent use.
Package clock is a low consumption, low latency support for frequent updates of large capacity timing manager: 基本处理逻辑: 使用方式,参见示例代码。
Package clockwerk implements an in-process scheduler for periodic jobs. Callers may register Jobs to be invoked on a given schedule. Clockwerk will run them in their own goroutines.
Package clock implements a library for mocking time. Include a Clock variable on your application and initialize it with a Realtime() by default. Then use the Clock for all time-related API calls. So instead of time.NewTimer(), say myClock.NewTimer(). On a test setup, override or inject the variable with a Mock instance and use it to control how the time behaves during each test phase. To mock context.WithTimeout and context.WithDeadline, use the included Context, TimeoutContext and DeadlineContext methods. The Context method is also useful in cases where you need to pass a Clock via an 'func(ctx Context, ..)' API you can't change yourself. The FromContext method will then return the associated Clock instance. Alternatively, use the context'ed methods like Sleep(ctx) directly. All methods are safe for concurrent use.