MCPcopy
hub / github.com/g3n/engine / setTimer

Method setTimer

core/timer.go:96–122  ·  view source on GitHub ↗

setTimer sets a new timer with the specified duration

(td time.Duration, periodic bool, arg interface{}, cb TimerCallback)

Source from the content-addressed store, hash-verified

94
95// setTimer sets a new timer with the specified duration
96func (tm *TimerManager) setTimer(td time.Duration, periodic bool, arg interface{}, cb TimerCallback) int {
97
98 // Creates timeout entry
99 t := timeout{
100 id: tm.nextID,
101 expire: time.Now().Add(td),
102 cb: cb,
103 arg: arg,
104 period: 0,
105 }
106 if periodic {
107 t.period = td
108 }
109 tm.nextID++
110
111 // Look for empty entry
112 for pos, ct := range tm.timers {
113 if ct.id == 0 {
114 tm.timers[pos] = t
115 return t.id
116 }
117 }
118
119 // If no empty entry found, add to end of array
120 tm.timers = append(tm.timers, t)
121 return t.id
122}

Callers 2

SetTimeoutMethod · 0.95
SetIntervalMethod · 0.95

Calls 1

AddMethod · 0.45

Tested by

no test coverage detected