package fakeclock

Import Path
	go.pact.im/x/clock/fakeclock (on go.dev)

Dependency Relation
	imports 4 packages, and imported by 0 packages

Involved Source Files Package fakeclock provides support for testing users of a clock.
Code Examples { var c Clock var wg sync.WaitGroup for i := 0; i < 3; i++ { i := i timer := c.Timer(time.Duration(i+1) * time.Second) wg.Add(1) go func() { defer wg.Done() defer timer.Stop() now := <-timer.C() fmt.Printf("timer %d fired at %v\n", i, now) }() } for { if _, ok := c.Next(); !ok { break } } wg.Wait() }
Package-Level Type Names (total 5, in which 1 are exported)
/* sort exporteds by: | */
Clock is a fake clock.Scheduler interface implementation that is safe for concurrent use by multiple goroutines. Use Next, Set, Add and AddDate methods to change clock time. Advancing the time triggers scheduled events, timers and tickers. Note that the order in which events scheduled for the same time are triggered is undefined, but it is guaranteed that all events that are not after the new current time are triggered on clock time change (even if old time is equal to the next time value). The zero Clock defaults to zero time and is ready for use. Add adds the given duration to the current time and returns the resulting clock time. It is possible to add a negative duration. It is safe for concurrent use and is a shorthand for now := c.Now().Add(d) c.Set(now) AddDate adds the duration corresponding to the given number of years, months and days relative to the current time and returns the resulting clock time. It is possible to add negative values. It is safe for concurrent use and is a shorthand for now := c.Now().AddDate(years, months, days) c.Set(now) Next advances the time to the next timer or ticker event and returns the new current time. If there are events in the past, the time is not changed. It returns false if there are no scheduled events. Otherwise it returns true and runs at least one scheduled event. Now returns the current clock time. Schedule implements the clock.Scheduler interface. Set sets the given time to be the current clock time. It is possible to set t that is before the current clock time. Ticker implements the clock.TickerScheduler interface. Note that the returned ticker does not adjust the time interval or drop ticks to make up for slow receivers. Timer implements the clock.TimerScheduler interface. *Clock : go.pact.im/x/clock.NowScheduler *Clock : go.pact.im/x/clock.Scheduler *Clock : go.pact.im/x/clock.TickerScheduler *Clock : go.pact.im/x/clock.TimerScheduler func Go() *Clock func Time(now time.Time) *Clock func Unix() *Clock func Y2038(d time.Duration) *Clock
Package-Level Functions (total 4, all are exported)
Go returns a clock set to the Go initial release date. That is, it is set to 2009-11-10 23:00:00 UTC.
Time returns a clock set to the given now time.
Unix returns a clock set to the Unix epoch time. That is, it is set to 1970-01-01 00:00:00 UTC.
Y2038 returns a clock set to d duration after the Year 2038 problem time. That is, it is set to the given duration after 2038-01-19 03:14:07 UTC, the latest time that can be properly encoded as a 32-bit integer that is a number of seconds after the Unix epoch.