1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
8
// Clock provides an interface for dealing with clocks.
11
// Now returns the current clock time.
14
// After waits for the duration to elapse and then sends the
15
// current time on the returned channel.
16
After(time.Duration) <-chan time.Time
18
// AfterFunc waits for the duration to elapse and then calls f in its own goroutine.
19
// It returns a Timer that can be used to cancel the call using its Stop method.
20
AfterFunc(time.Duration, func()) Timer
23
// Alarm returns a channel that will have the time sent on it at some point
24
// after the supplied time occurs.
26
// This is short for c.After(t.Sub(c.Now())).
27
func Alarm(c Clock, t time.Time) <-chan time.Time {
28
return c.After(t.Sub(c.Now()))
31
// The Timer type represents a single event.
32
// A Timer must be created with AfterFunc.
33
// This interface follows time.Timer's methods but provides easier mocking.
34
type Timer interface {
36
// Reset changes the timer to expire after duration d.
37
// It returns true if the timer had been active, false if
38
// the timer had expired or been stopped.
39
Reset(time.Duration) bool
41
// Stop prevents the Timer from firing. It returns true if
42
// the call stops the timer, false if the timer has already expired or been stopped.
43
// Stop does not close the channel, to prevent a read
44
// from the channel succeeding incorrectly.