goTimeWheel

package module
v0.0.0-...-eaec46e Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2019 License: MIT Imports: 2 Imported by: 0

README

goTimeWheel

Build Status codecov GoDoc

TimeWheel Implemented By Go. Go 实现的时间轮,俗称定时器 Link

goTimeWheel

Feature

  • Effective at Space Usage
  • Each Timer Can Custom Its Task

Installation

go get github.com/zheng-ji/goTimeWheel

Example

import (
    "fmt"
    "github.com/zheng-ji/goTimeWheel"
)

func main() {
    // timer ticker
    tw := goTimeWheel.New(1*time.Second, 3600)
    tw.Start()

    // "ID1" means the timer's name
    // Specify a function and params, it will run after 3s later
    name := "ID1"
    params := map[string]int{"age": 1}
    fn := func(data interface{}) {
        fmt.Printf("hello, %v\n", data)
    }
    tw.AddTimer(3*time.Second, name, fn, params)

    // Your Logic Code
    select{}

}

License

Copyright (c) 2019 by zheng-ji released under MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Task

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

Task Struct

type TimeWheel

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

TimeWheel Struct

func New

func New(interval time.Duration, slotNum int) *TimeWheel

New Func: Generate TimeWheel with ticker and slotNum

func (*TimeWheel) AddTimer

func (tw *TimeWheel) AddTimer(delay time.Duration, key interface{}, fn func(interface{}), params interface{})

func (*TimeWheel) RemoveTimer

func (tw *TimeWheel) RemoveTimer(key interface{})

func (*TimeWheel) Start

func (tw *TimeWheel) Start()

Start Func: start ticker and monitor channel

func (*TimeWheel) Stop

func (tw *TimeWheel) Stop()

Jump to

Keyboard shortcuts

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