CancelTimer 取消计时器
(key uint32)
| 119 | |
| 120 | // CancelTimer 取消计时器 |
| 121 | func (c *Clock) CancelTimer(key uint32) bool { |
| 122 | t, ok := c.GetTimer(key) |
| 123 | if ok { |
| 124 | if t.Cron != "" { |
| 125 | c.entmu.Lock() |
| 126 | e := c.entries[key] |
| 127 | c.cron.Remove(e) |
| 128 | delete(c.entries, key) |
| 129 | c.entmu.Unlock() |
| 130 | } else { |
| 131 | t.SetEn(false) |
| 132 | } |
| 133 | c.timersmu.Lock() |
| 134 | delete(*c.timers, key) // 避免重复取消 |
| 135 | e := c.db.Del("timer", "WHERE id = ?", key) |
| 136 | c.timersmu.Unlock() |
| 137 | return e == nil |
| 138 | } |
| 139 | return false |
| 140 | } |
| 141 | |
| 142 | // ListTimers 列出本群所有计时器 |
| 143 | func (c *Clock) ListTimers(grpID int64) []string { |