Documentation ¶
Overview ¶
Package gxtime encapsulates some golang.time functions
Package gxtime encapsulates some golang.time functions ¶
Package gxtime encapsulates some golang.time functions ¶
Package gxtime encapsulates some golang.time functions ¶
Package gxtime encapsulates some golang.time functions ¶
Package gxtime encapsulates some golang.time functions ref: https://github.com/AlexStocks/go-practice/blob/master/time/siddontang_time_wheel.go
Index ¶
- Constants
- Variables
- func After(d time.Duration) <-chan time.Time
- func Future(sec int, f func())
- func GetEndTime(format string) time.Time
- func InitDefaultTimerWheel()
- func Now() time.Time
- func Sleep(d time.Duration)
- func Tick(d time.Duration) <-chan time.Time
- func Time2Unix(t time.Time) int64
- func Time2UnixNano(t time.Time) int64
- func TimeDayDuration(day float64) time.Duration
- func TimeHourDuration(hour float64) time.Duration
- func TimeMicrosecondDuration(m float64) time.Duration
- func TimeMillisecondDuration(m float64) time.Duration
- func TimeMinuteDuration(minute float64) time.Duration
- func TimeNanosecondDuration(n float64) time.Duration
- func TimeSecondDuration(sec float64) time.Duration
- func Unix2Time(unix int64) time.Time
- func UnixNano2Time(nano int64) time.Time
- func UnixString2Time(unix string) time.Time
- func YMD(year int, month int, day int, hour int, minute int, sec int) int
- func YMDPrint(sec int, nsec int) string
- func YMDUTC(year int, month int, day int, hour int, minute int, sec int) int
- type CountWatch
- type Ticker
- type Timer
- type TimerFunc
- type TimerID
- type TimerType
- type TimerWheel
- func (w *TimerWheel) AddTimer(f TimerFunc, typ TimerType, period time.Duration, arg interface{}) (*Timer, error)
- func (w *TimerWheel) After(d time.Duration) <-chan time.Time
- func (w *TimerWheel) AfterFunc(d time.Duration, f func()) *Timer
- func (w *TimerWheel) Close()
- func (w *TimerWheel) NewTicker(d time.Duration) *Ticker
- func (w *TimerWheel) NewTimer(d time.Duration) *Timer
- func (w *TimerWheel) Now() time.Time
- func (w *TimerWheel) Sleep(d time.Duration)
- func (w *TimerWheel) Stop()
- func (w *TimerWheel) Tick(d time.Duration) <-chan time.Time
- func (w *TimerWheel) TickFunc(d time.Duration, f func()) *Ticker
- func (w *TimerWheel) TimerNumber() int
- type Wheel
Constants ¶
const ( TimerActionAdd timerAction = 1 TimerActionDel timerAction = 2 TimerActionReset timerAction = 3 )
Variables ¶
var ErrTimeChannelClosed = errors.New("timer channel closed")
nolint
Functions ¶
func After ¶
After waits for the duration to elapse and then sends the current time on the returned channel.
func GetEndTime ¶
func InitDefaultTimerWheel ¶
func InitDefaultTimerWheel()
InitDefaultTimerWheel initializes a default timer wheel
func Sleep ¶
Sleep pauses the current goroutine for at least the duration d. A negative or zero duration causes Sleep to return immediately.
func Tick ¶
Tick is a convenience wrapper for NewTicker providing access to the ticking channel only. While Tick is useful for clients that have no need to shut down the Ticker, be aware that without a way to shut it down the underlying Ticker cannot be recovered by the garbage collector; it "leaks". Unlike NewTicker, Tick will return nil if d <= 0.
func Time2UnixNano ¶
func TimeDayDuration ¶
func TimeHourDuration ¶
func TimeMicrosecondDuration ¶
func TimeMillisecondDuration ¶
func TimeMinuteDuration ¶
func TimeNanosecondDuration ¶
func TimeSecondDuration ¶
func UnixNano2Time ¶
func UnixString2Time ¶
Types ¶
type CountWatch ¶
type CountWatch struct {
// contains filtered or unexported fields
}
func (*CountWatch) Count ¶
func (w *CountWatch) Count() int64
func (*CountWatch) Reset ¶
func (w *CountWatch) Reset()
func (*CountWatch) Start ¶
func (w *CountWatch) Start()
type Ticker ¶
Ticker is a wrapper of TimerWheel in golang Ticker style
type Timer ¶
Timer is a wrapper of TimeWheel to supply go timer funcs
func AfterFunc ¶
AfterFunc waits for the duration to elapse and then calls f in its own goroutine. It returns a Timer that can be used to cancel the call using its Stop method.
func NewTimer ¶
NewTimer creates a new Timer that will send the current time on its channel after at least duration d.
type TimerFunc ¶
TimerFunc defines the time func. if the return error is not nil, the related timer will be closed.
type TimerWheel ¶
type TimerWheel struct {
// contains filtered or unexported fields
}
TimerWheel is a timer based on multiple wheels
func GetDefaultTimerWheel ¶
func GetDefaultTimerWheel() *TimerWheel
func (*TimerWheel) AddTimer ¶
func (w *TimerWheel) AddTimer(f TimerFunc, typ TimerType, period time.Duration, arg interface{}) (*Timer, error)
AddTimer adds a timer asynchronously and returns a timer struct obj. It returns error if it failed.
Attention that @f may block the timer gr. So u should create a gr to exec ur function asynchronously if it may take a long time.
args:
@f: timer function. @typ: timer type @period: timer loop interval. its unit is nanosecond. @arg: timer argument which is used by @f.
func (*TimerWheel) After ¶
func (w *TimerWheel) After(d time.Duration) <-chan time.Time
After waits for the duration to elapse and then sends the current time on the returned channel.
func (*TimerWheel) AfterFunc ¶
func (w *TimerWheel) AfterFunc(d time.Duration, f func()) *Timer
AfterFunc waits for the duration to elapse and then calls f in its own goroutine. It returns a Timer that can be used to cancel the call using its Stop method.
func (*TimerWheel) Close ¶
func (w *TimerWheel) Close()
Close stops the timer wheel and wait for all grs.
func (*TimerWheel) NewTicker ¶
func (w *TimerWheel) NewTicker(d time.Duration) *Ticker
NewTicker returns a new Ticker containing a channel that will send the time on the channel after each tick. The period of the ticks is specified by the duration argument. The ticker will adjust the time interval or drop ticks to make up for slow receivers. The duration d must be greater than zero; if not, NewTicker will panic. Stop the ticker to release associated resources.
func (*TimerWheel) NewTimer ¶
func (w *TimerWheel) NewTimer(d time.Duration) *Timer
NewTimer creates a new Timer that will send the current time on its channel after at least duration d.
func (*TimerWheel) Sleep ¶
func (w *TimerWheel) Sleep(d time.Duration)
Sleep pauses the current goroutine for at least the duration d. A negative or zero duration causes Sleep to return immediately.
func (*TimerWheel) Tick ¶
func (w *TimerWheel) Tick(d time.Duration) <-chan time.Time
Tick is a convenience wrapper for NewTicker providing access to the ticking channel only. While Tick is useful for clients that have no need to shut down the Ticker, be aware that without a way to shut it down the underlying Ticker cannot be recovered by the garbage collector; it "leaks". Unlike NewTicker, Tick will return nil if d <= 0.
func (*TimerWheel) TickFunc ¶
func (w *TimerWheel) TickFunc(d time.Duration, f func()) *Ticker
TickFunc returns a Ticker
func (*TimerWheel) TimerNumber ¶
func (w *TimerWheel) TimerNumber() int
TimerNumber returns the timer obj number in wheel