-
Notifications
You must be signed in to change notification settings - Fork 6
/
slot.go
56 lines (46 loc) · 926 Bytes
/
slot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package timer
import (
"github.com/singchia/go-timer/v2/pkg/linker"
)
type slot struct {
dlinker *linker.Doublinker
w *wheel
}
func newSlot(w *wheel) *slot {
return &slot{w: w, dlinker: linker.NewDoublinker()}
}
func (s *slot) length() int64 {
return s.dlinker.Length()
}
func (s *slot) add(tick *tick) *tick {
doubID := s.dlinker.Add(tick)
tick.id = doubID
tick.s = s
return tick
}
func (s *slot) delete(tick *tick) {
s.dlinker.Delete(tick.id)
}
func (s *slot) update(tick *tick, data interface{}) {
tick.data = data
}
func (s *slot) remove() *linker.Doublinker {
temp := s.dlinker
s.dlinker = linker.NewDoublinker()
return temp
}
func (s *slot) close() *linker.Doublinker {
if s == nil {
return nil
}
s.w = nil
temp := s.dlinker
s.dlinker = nil
return temp
}
func (s *slot) foreach(handler linker.ForeachFunc) error {
if s == nil {
return nil
}
return s.dlinker.Foreach(handler)
}