utils

package
v0.4.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// TimerPrecision indicates the precision of timer, default is time.Second
	TimerPrecision = time.Second

	// GlobalTicker represents global ticker that all cron job will be executed
	// in GlobalTicker.
	GlobalTicker *time.Ticker
)
View Source
var (
	ListenAddr string
)

Default serializer

Functions

func Cron

func Cron()

func FileExists

func FileExists(filename string) bool

func GenerateLocalAddr

func GenerateLocalAddr() string

func GenerateNodeId

func GenerateNodeId(ntype nodes.NodeType, gsid string) string

func GenerateTopic

func GenerateTopic(s ...string) string

func GobDecode

func GobDecode(reply interface{}, data []byte) error

func GobEncode

func GobEncode(args ...interface{}) ([]byte, error)

func InArray

func InArray(needle interface{}, haystack interface{}) bool

func IndexOf

func IndexOf(a []interface{}, e interface{}, cmp CompareFunc) int

func Int64ToString

func Int64ToString(valint int64) string

func Int64Toint

func Int64Toint(valint int64) int

func IntToInt64

func IntToInt64(valint int) int64

func IntToString

func IntToString(intval int) string

func Md5

func Md5(sign string) string

func SerializeOrRaw

func SerializeOrRaw(v interface{}) ([]byte, error)

func SetTimerPrecision

func SetTimerPrecision(precision time.Duration)

SetTimerPrecision set the ticker precision, and time precision can not less than a Millisecond, and can not change after application running. The default precision is time.Second

func Stack

func Stack() string

func StringToInt

func StringToInt(valstr string) int

func StringToInt64

func StringToInt64(valstr string) int64

func Time

func Time() int

Types

type CompareFunc

type CompareFunc func(interface{}, interface{}) bool

type Timer

type Timer struct {
	// contains filtered or unexported fields
}

Timer represents a cron job

func NewAfterTimer

func NewAfterTimer(duration time.Duration, fn TimerFunc) *Timer

NewAfterTimer returns a new Timer containing a function that will be called after duration that specified by the duration argument. The duration d must be greater than zero; if not, NewAfterTimer will panic. Stop the timer to release associated resources.

func NewCondTimer

func NewCondTimer(condition TimerCondition, fn TimerFunc) *Timer

NewCondTimer returns a new Timer containing a function that will be called when condition satisfied that specified by the condition argument. The duration d must be greater than zero; if not, NewCondTimer will panic. Stop the timer to release associated resources.

func NewCountTimer

func NewCountTimer(interval time.Duration, count int, fn TimerFunc) *Timer

NewCountTimer returns a new Timer containing a function that will be called with a period specified by the duration argument. After count times, timer will be stopped automatically, It adjusts the intervals for slow receivers. The duration d must be greater than zero; if not, NewCountTimer will panic. Stop the timer to release associated resources.

func NewTimer

func NewTimer(interval time.Duration, fn TimerFunc) *Timer

NewTimer returns a new Timer containing a function that will be called with a period specified by the duration argument. It adjusts the intervals for slow receivers. The duration d must be greater than zero; if not, NewTimer will panic. Stop the timer to release associated resources.

func (*Timer) ID

func (t *Timer) ID() int64

ID returns id of current timer

func (*Timer) Stop

func (t *Timer) Stop()

Stop turns off a timer. After Stop, fn will not be called forever

type TimerCondition

type TimerCondition interface {
	Check(now time.Time) bool
}

TimerCondition represents a checker that returns true when cron job needs to execute

type TimerFunc

type TimerFunc func()

TimerFunc represents a function which will be called periodically in main logic gorontine.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL