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 TimeDayDuratioin(day float64) time.Duration
- func TimeHourDuratioin(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 ( ADD_TIMER timerAction = 1 DEL_TIMER timerAction = 2 RESET_TIMER timerAction = 3 )
Variables ¶
var ( // nolint ErrTimeChannelFull = errors.New("timer channel full") // nolint ErrTimeChannelClosed = errors.New("timer channel closed") )
Functions ¶
func After ¶ added in v1.9.10
After waits for the duration to elapse and then sends the current time on the returned channel.
func GetEndtime ¶
func InitDefaultTimerWheel ¶ added in v1.9.10
func InitDefaultTimerWheel()
InitDefaultTimerWheel initializes a default timer wheel
func Sleep ¶ added in v1.9.10
Sleep pauses the current goroutine for at least the duration d. A negative or zero duration causes Sleep to return immediately.
func Tick ¶ added in v1.9.10
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 TimeDayDuratioin ¶
func TimeHourDuratioin ¶
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 ¶ added in v1.9.10
Ticker is a wrapper of TimerWheel in golang Ticker style
type Timer ¶ added in v1.9.10
Timer is a wrapper of TimeWheel to supply go timer funcs
func AfterFunc ¶ added in v1.9.10
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 ¶ added in v1.9.10
NewTimer creates a new Timer that will send the current time on its channel after at least duration d.
type TimerFunc ¶ added in v1.9.10
TimerFunc defines the time func. if the return error is not nil, the related timer will be closed.
type TimerWheel ¶ added in v1.9.10
type TimerWheel struct {
// contains filtered or unexported fields
}
TimerWheel is a timer based on multiple wheels
func GetDefaultTimerWheel ¶ added in v1.9.10
func GetDefaultTimerWheel() *TimerWheel
func NewTimerWheel ¶ added in v1.9.10
func NewTimerWheel() *TimerWheel
NewTimerWheel returns a @TimerWheel object.
func (*TimerWheel) AddTimer ¶ added in v1.9.10
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 ¶ added in v1.9.10
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 ¶ added in v1.9.10
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 ¶ added in v1.9.10
func (w *TimerWheel) Close()
Close stops the timer wheel and wait for all grs.
func (*TimerWheel) NewTicker ¶ added in v1.9.10
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 ¶ added in v1.9.10
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) Now ¶ added in v1.9.10
func (w *TimerWheel) Now() time.Time
Now returns the current time
func (*TimerWheel) Sleep ¶ added in v1.9.10
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 ¶ added in v1.9.10
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 ¶ added in v1.9.10
func (w *TimerWheel) TickFunc(d time.Duration, f func()) *Ticker
TickFunc returns a Ticker
func (*TimerWheel) TimerNumber ¶ added in v1.9.10
func (w *TimerWheel) TimerNumber() int
TimerNumber returns the timer obj number in wheel