github.com/rogpeppe/clock@v0.0.0-20190514195947-2896927a307a/wall.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the LGPLv3, see LICENCE file for details.
     3  
     4  package clock
     5  
     6  import (
     7  	"time"
     8  )
     9  
    10  // WallClock exposes wall-clock time via the Clock interface.
    11  var WallClock wallClock
    12  
    13  // ensure that WallClock does actually implement the Clock interface.
    14  var _ Clock = WallClock
    15  
    16  // WallClock exposes wall-clock time as returned by time.Now.
    17  type wallClock struct{}
    18  
    19  // Now is part of the Clock interface.
    20  func (wallClock) Now() time.Time {
    21  	return time.Now()
    22  }
    23  
    24  // After implements Clock.After.
    25  func (wallClock) After(d time.Duration) <-chan time.Time {
    26  	return time.After(d)
    27  }
    28  
    29  // AfterFunc implements Clock.AfterFunc.
    30  func (wallClock) AfterFunc(d time.Duration, f func()) Timer {
    31  	return wallTimer{time.AfterFunc(d, f)}
    32  }
    33  
    34  // NewTimer implements Clock.NewTimer.
    35  func (wallClock) NewTimer(d time.Duration) Timer {
    36  	return wallTimer{time.NewTimer(d)}
    37  }
    38  
    39  // wallTimer implements the Timer interface.
    40  type wallTimer struct {
    41  	*time.Timer
    42  }
    43  
    44  // Chan implements Timer.Chan.
    45  func (t wallTimer) Chan() <-chan time.Time {
    46  	return t.C
    47  }