func (tw *TimeWheel) run() {
	for {
		select {
		case <-tw.quitChan:
			tw.ticker.Stop()
			break
		case <-tw.ticker.C:
			tw.mux.Lock()
			if tw.ticksOfWheel == tw.currentTickIndex {
				tw.currentTickIndex = 0
			}
			slot := tw.wheel[tw.currentTickIndex]
			for _, v := range slot.elements {
				slot.remove(v)
				delete(tw.indicator, v)
				tw.onTick(tw.fmanager, v)
			}
			tw.currentTickIndex++
			tw.mux.Unlock()
		case v := <-tw.taskChan:
			c := v.(string)
			tw.Remove(c)
			slot := tw.wheel[tw.getPreviousTickIndex()]
			tw.mux.Lock()
			slot.add(c)
			tw.indicator[c] = slot
			tw.mux.Unlock()
		}
	}
}
The internal run function, manage all slots and interface
package timewheel
import (
	"sync"
	"time"
)
type slot struct {
	mux      *sync.Mutex
	id       int
	elements map[interface{}]interface{}
}
func newSlot(id int) *slot {
	s := &slot{
		id:  id,
		mux: new(sync.Mutex),
	}
	s.elements = make(map[interface{}]interface{})
	return s
}
func (s *slot) add(c interface{}) {
	s.mux.Lock()
	defer s.mux.Unlock()
	s.elements[c] = c
}
func (s *slot) remove(c interface{}) {
	s.mux.Lock()
	defer s.mux.Unlock()
	delete(s.elements, c)
}
type handler func(manager interface{}, u interface{})
type TimeWheel struct {
	mux              *sync.Mutex
	fmanager         interface{}
	tickDuration     time.Duration
	ticksOfWheel     int
	currentTickIndex int
	ticker           *time.Ticker
	onTick           handler
	wheel            []*slot
	indicator        map[interface{}]*slot
	taskChan chan interface{}
	quitChan chan interface{}
}
func NewTimeWheel(tickDuration time.Duration, ticksOfWheel int, f handler, manager interface{}) *TimeWheel {
	if tickDuration < 1 || ticksOfWheel < 1 || nil == f {
		return nil
	}
	ticksOfWheel++
	tw := &TimeWheel{
		fmanager:         manager,
		tickDuration:     tickDuration,
		ticksOfWheel:     ticksOfWheel,
		onTick:           f,
		currentTickIndex: 0,
		taskChan:         make(chan interface{}, 10),
		quitChan:         make(chan interface{}, 10),
		mux:              new(sync.Mutex),
	}
	tw.indicator = make(map[interface{}]*slot, 0)
	tw.wheel = make([]*slot, ticksOfWheel)
	for i := 0; i < ticksOfWheel; i++ {
		tw.wheel[i] = newSlot(i)
	}
	return tw
}
func (tw *TimeWheel) Start() {
	tw.ticker = time.NewTicker(tw.tickDuration)
	go tw.run()
}
func (tw *TimeWheel) Add(c interface{}) {
	tw.taskChan <- c
}
func (tw *TimeWheel) Remove(c interface{}) {
	tw.mux.Lock()
	defer tw.mux.Unlock()
	if v, ok := tw.indicator[c]; ok {
		v.remove(c)
	}
}
func (tw *TimeWheel) getPreviousTickIndex() int {
	tw.mux.Lock()
	defer tw.mux.Unlock()
	cti := tw.currentTickIndex
	if 0 == cti {
		return tw.ticksOfWheel - 1
	}
	return cti - 1
}
func (tw *TimeWheel) Stop() {
	close(tw.quitChan)
}