Documentation ¶
Overview ¶
Example (Add) ¶
package main import ( "fmt" "github.com/osgochina/donkeygo/os/dtimer" "time" ) func main() { now := time.Now() interval := 1400 * time.Millisecond dtimer.Add(interval, func() { fmt.Println(time.Now(), time.Duration(time.Now().UnixNano()-now.UnixNano())) now = time.Now() }) select {} }
Output:
Index ¶
- Constants
- func DelayAdd(delay time.Duration, interval time.Duration, job JobFunc)
- func DelayAddEntry(delay time.Duration, interval time.Duration, job JobFunc, singleton bool, ...)
- func DelayAddOnce(delay time.Duration, interval time.Duration, job JobFunc)
- func DelayAddSingleton(delay time.Duration, interval time.Duration, job JobFunc)
- func DelayAddTimes(delay time.Duration, interval time.Duration, times int, job JobFunc)
- func Exit()
- func SetInterval(interval time.Duration, job JobFunc)
- func SetTimeout(delay time.Duration, job JobFunc)
- type Entry
- func Add(interval time.Duration, job JobFunc) *Entry
- func AddEntry(interval time.Duration, job JobFunc, singleton bool, times int, status int) *Entry
- func AddOnce(interval time.Duration, job JobFunc) *Entry
- func AddSingleton(interval time.Duration, job JobFunc) *Entry
- func AddTimes(interval time.Duration, times int, job JobFunc) *Entry
- func (that *Entry) Close()
- func (that *Entry) IsSingleton() bool
- func (that *Entry) Job() JobFunc
- func (that *Entry) Reset()
- func (that *Entry) Run()
- func (that *Entry) SetSingleton(enabled bool)
- func (that *Entry) SetStatus(status int) int
- func (that *Entry) SetTimes(times int)
- func (that *Entry) Start()
- func (that *Entry) Status() int
- func (that *Entry) Stop()
- type JobFunc
- type Timer
- func (that *Timer) Add(interval time.Duration, job JobFunc) *Entry
- func (that *Timer) AddEntry(interval time.Duration, job JobFunc, singleton bool, times int, status int) *Entry
- func (that *Timer) AddOnce(interval time.Duration, job JobFunc) *Entry
- func (that *Timer) AddSingleton(interval time.Duration, job JobFunc) *Entry
- func (that *Timer) AddTimes(interval time.Duration, times int, job JobFunc) *Entry
- func (that *Timer) Close()
- func (that *Timer) DelayAdd(delay time.Duration, interval time.Duration, job JobFunc)
- func (that *Timer) DelayAddEntry(delay time.Duration, interval time.Duration, job JobFunc, singleton bool, ...)
- func (that *Timer) DelayAddOnce(delay time.Duration, interval time.Duration, job JobFunc)
- func (that *Timer) DelayAddSingleton(delay time.Duration, interval time.Duration, job JobFunc)
- func (that *Timer) DelayAddTimes(delay time.Duration, interval time.Duration, times int, job JobFunc)
- func (that *Timer) Start()
- func (that *Timer) Stop()
- type TimerOptions
Examples ¶
Constants ¶
View Source
const ( StatusReady = 0 // 定时器准备好了,随时可以运行 StatusRunning = 1 // 定时器运行中 StatusStopped = 2 // 定时器已经停止了 StatusClosed = -1 // 定时器已经关闭,等待被删除 )
Variables ¶
This section is empty.
Functions ¶
func DelayAddEntry ¶
func DelayAddEntry(delay time.Duration, interval time.Duration, job JobFunc, singleton bool, times int, status int)
DelayAddEntry 延迟添加任务
func DelayAddOnce ¶
DelayAddOnce 延迟添加一次性任务
func DelayAddSingleton ¶
DelayAddSingleton 延迟添加并发限制任务
func DelayAddTimes ¶
DelayAddTimes 延迟添加指定执行次数的任务
Types ¶
type Entry ¶
type Entry struct {
// contains filtered or unexported fields
}
Entry 定时器要执行的任务
func AddSingleton ¶
AddSingleton 添加并发限制任务
type Timer ¶
type Timer struct {
// contains filtered or unexported fields
}
Timer 定时器对象
func (*Timer) AddEntry ¶
func (that *Timer) AddEntry(interval time.Duration, job JobFunc, singleton bool, times int, status int) *Entry
AddEntry 添加定时任务 interval 执行间隔 job 要执行的任务 singleton 是否并发限制 times 要执行的次数 status 默认状态
func (*Timer) AddSingleton ¶
AddSingleton 添加并发限制任务
func (*Timer) DelayAddEntry ¶
func (that *Timer) DelayAddEntry(delay time.Duration, interval time.Duration, job JobFunc, singleton bool, times int, status int)
DelayAddEntry 延迟添加更详细参数的任务
func (*Timer) DelayAddOnce ¶
DelayAddOnce 延迟添加执行一次任务
func (*Timer) DelayAddSingleton ¶
DelayAddSingleton 延迟添加并发限制任务
type TimerOptions ¶ added in v0.1.9
Click to show internal directories.
Click to hide internal directories.