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.
musync.Mutexnowtime.Timeschedmap[moment]time.Time
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.
advance runs the scheduled events for the current clock time.
next returns the time of the next scheduled event. It returns the given now
time if there are no events or some of them are in the past.
reset resets the given moment to run d duration after the current time.
Note that reset acquires the underlying lock. Reset returns true if it
rescheduled an event.
schedule schedules the given moment to run on next clock advance. It returns
true if an event was rescheduled.
stop removes the given moment from the set of scheduled events. It returns
true if stop prevented the event from firing. Note that stop acquires the
underlying lock.
*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
event implements the moment and clock.Event interfaces.
c*Clockffunc(time.Time)
Reset implements the clock.Event interface.
Stop implements the clock.Event interface.
next implements the moment interface.
*event : go.pact.im/x/clock.Event
*event : moment
ticker implements the moment and clock.Ticker interfaces.
c*Clockchchan time.Timedtime.Duration
C implements the clock.Ticker interface.
Reset implements the clock.Ticker interface.
Stop implements the clock.Ticker interface.
next implements the moment interface.
*ticker : go.pact.im/x/clock.Ticker
*ticker : moment
timer implements the moment and clock.Timer interfaces.
c*Clockchchan time.Time
C implements the clock.Timer interface.
Reset implements the clock.Timer interface.
Stop implements the clock.Timer interface.
next implements the moment interface.
*timer : go.pact.im/x/clock.Timer
*timer : moment
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.
The pages are generated with Goldsv0.4.9. (GOOS=linux GOARCH=amd64)