dtimer

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 6 Imported by: 0

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

Examples

Constants

View Source
const (
	StatusReady   = 0  // 定时器准备好了,随时可以运行
	StatusRunning = 1  // 定时器运行中
	StatusStopped = 2  // 定时器已经停止了
	StatusClosed  = -1 // 定时器已经关闭,等待被删除

)

Variables

This section is empty.

Functions

func DelayAdd

func DelayAdd(delay time.Duration, interval time.Duration, job JobFunc)

DelayAdd 延迟添加任务

func DelayAddEntry

func DelayAddEntry(delay time.Duration, interval time.Duration, job JobFunc, singleton bool, times int, status int)

DelayAddEntry 延迟添加任务

func DelayAddOnce

func DelayAddOnce(delay time.Duration, interval time.Duration, job JobFunc)

DelayAddOnce 延迟添加一次性任务

func DelayAddSingleton

func DelayAddSingleton(delay time.Duration, interval time.Duration, job JobFunc)

DelayAddSingleton 延迟添加并发限制任务

func DelayAddTimes

func DelayAddTimes(delay time.Duration, interval time.Duration, times int, job JobFunc)

DelayAddTimes 延迟添加指定执行次数的任务

func Exit

func Exit()

Exit 退出该任务,不再触发后续的执行

func SetInterval

func SetInterval(interval time.Duration, job JobFunc)

SetInterval 设置执行时间循环执行的任务

func SetTimeout

func SetTimeout(delay time.Duration, job JobFunc)

SetTimeout 设置延迟执行的一次性任务

Types

type Entry

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

Entry 定时器要执行的任务

func Add

func Add(interval time.Duration, job JobFunc) *Entry

Add 设置执行时间循环执行的任务

func AddEntry

func AddEntry(interval time.Duration, job JobFunc, singleton bool, times int, status int) *Entry

AddEntry 通过参数设置任务

func AddOnce

func AddOnce(interval time.Duration, job JobFunc) *Entry

AddOnce 添加一次性任务

func AddSingleton

func AddSingleton(interval time.Duration, job JobFunc) *Entry

AddSingleton 添加并发限制任务

func AddTimes

func AddTimes(interval time.Duration, times int, job JobFunc) *Entry

AddTimes 添加指定执行次数的任务

func (*Entry) Close

func (that *Entry) Close()

Close 关闭该任务

func (*Entry) IsSingleton

func (that *Entry) IsSingleton() bool

IsSingleton 判断任务是否是并发限制任务

func (*Entry) Job added in v0.1.9

func (that *Entry) Job() JobFunc

Job 当前定时任务需要执行的方法

func (*Entry) Reset

func (that *Entry) Reset()

Reset 重置任务运行节拍器

func (*Entry) Run

func (that *Entry) Run()

Run 运行任务

func (*Entry) SetSingleton

func (that *Entry) SetSingleton(enabled bool)

SetSingleton 设置任务为并发限制任务

func (*Entry) SetStatus

func (that *Entry) SetStatus(status int) int

SetStatus 修改任务状态

func (*Entry) SetTimes

func (that *Entry) SetTimes(times int)

SetTimes 设置任务执行次数

func (*Entry) Start

func (that *Entry) Start()

Start 启动任务,把任务状态修改为准备执行

func (*Entry) Status

func (that *Entry) Status() int

Status 获取当前任务的状态

func (*Entry) Stop

func (that *Entry) Stop()

Stop 停止任务,把任务修正为停止状态,不同于close任务,停止状态可以从新开始

type JobFunc

type JobFunc = func()

type Timer

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

Timer 定时器对象

func New added in v0.1.9

func New(options ...TimerOptions) *Timer

New 新建一个定时器

func (*Timer) Add

func (that *Timer) Add(interval time.Duration, job JobFunc) *Entry

Add 添加定时任务

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) AddOnce

func (that *Timer) AddOnce(interval time.Duration, job JobFunc) *Entry

AddOnce 添加只执行一次任务

func (*Timer) AddSingleton

func (that *Timer) AddSingleton(interval time.Duration, job JobFunc) *Entry

AddSingleton 添加并发限制任务

func (*Timer) AddTimes

func (that *Timer) AddTimes(interval time.Duration, times int, job JobFunc) *Entry

AddTimes 添加指定执行次数任务

func (*Timer) Close

func (that *Timer) Close()

Close 关闭定时器

func (*Timer) DelayAdd

func (that *Timer) DelayAdd(delay time.Duration, interval time.Duration, job JobFunc)

DelayAdd 延迟添加任务

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

func (that *Timer) DelayAddOnce(delay time.Duration, interval time.Duration, job JobFunc)

DelayAddOnce 延迟添加执行一次任务

func (*Timer) DelayAddSingleton

func (that *Timer) DelayAddSingleton(delay time.Duration, interval time.Duration, job JobFunc)

DelayAddSingleton 延迟添加并发限制任务

func (*Timer) DelayAddTimes

func (that *Timer) DelayAddTimes(delay time.Duration, interval time.Duration, times int, job JobFunc)

DelayAddTimes 延迟添加指定执行次数的任务

func (*Timer) Start

func (that *Timer) Start()

Start 启动定时器

func (*Timer) Stop

func (that *Timer) Stop()

Stop 停止定时器

type TimerOptions added in v0.1.9

type TimerOptions struct {
	Interval time.Duration // Interval 定时器的触发间隔
}

func DefaultOptions added in v0.1.9

func DefaultOptions() TimerOptions

DefaultOptions 获取默认的配置选项

Jump to

Keyboard shortcuts

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