timewheel

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2019 License: MIT Imports: 10 Imported by: 0

README

timewheel

a time wheel similar with Netty's HashedTimeWheel

Build Status Coverage Status Go Report Card GoDoc

Install
go get -u github.com/FelixSeptem/timewheel

Further reading:

Documentation

Overview

Package timewheel implement a time wheel similar with Netty's HashedTimeWheel

Index

Constants

View Source
const (
	DEFAULT_TIMEWHEEL_SLOTSNUM     = 3600
	DEFAULT_TIMEWHEEL_STEPDURATION = time.Microsecond
	DEFAULT_TIMEWHEEL_ERRORSIZE    = 1024
)

some default config parameters

View Source
const (
	TIMEWHEEL_RUNNING_STATUS_INIT = iota
	TIMEWHEEL_RUNNING_STATUS_RUNNING
	TIMEWHEEL_RUNNING_STATUS_END
)

timewheel running status

Variables

This section is empty.

Functions

This section is empty.

Types

type TaskHandler

type TaskHandler func() error

task handler function's signature

type TimeWheel

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

timewheel entity

func NewTimeWheel

func NewTimeWheel(name string, slotsNum int, stepDuration time.Duration, errSize int) *TimeWheel

return a new time wheel of given parameters for example: NewTimeWheel("example", 3600, time.Second, 100) will return a TimeWheel which has accuracy of 1 second and running around once an hour(3600 * 1s), it has an err channel to receive task handler's return err,which has 100 capacity.

func (*TimeWheel) AddTask

func (tw *TimeWheel) AddTask(delayDurations time.Duration, handler TaskHandler) (string, error)

add a new task into time wheel return task's ID

func (*TimeWheel) BQuit added in v0.1.1

func (tw *TimeWheel) BQuit() error

BQuit will blocking until all task in the timewheel has been finished,then quit

func (*TimeWheel) HandleErr

func (tw *TimeWheel) HandleErr() <-chan error

return task handler's errs to handle

func (*TimeWheel) Info

func (tw *TimeWheel) Info() (name string, startTime time.Time, capacity int64)

return time wheel's related information

func (*TimeWheel) Quit added in v0.1.1

func (tw *TimeWheel) Quit() error

quit timewheel may lost unfinished task, concurrent quit may cause panic due to golang's channel close principle

func (*TimeWheel) Run

func (tw *TimeWheel) Run() error

start time consume

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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