File: deadman.go

package info (click to toggle)
golang-github-slack-go-slack 0.11.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 1,720 kB
  • sloc: makefile: 54
file content (31 lines) | stat: -rw-r--r-- 540 bytes parent folder | download
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
package socketmode

import "time"

type deadmanTimer struct {
	timeout time.Duration
	timer   *time.Timer
}

func newDeadmanTimer(timeout time.Duration) *deadmanTimer {
	return &deadmanTimer{
		timeout: timeout,
		timer:   time.NewTimer(timeout),
	}
}

func (smc *deadmanTimer) Elapsed() <-chan time.Time {
	return smc.timer.C
}

func (smc *deadmanTimer) Reset() {
	// Note that this is the correct way to Reset a non-expired timer
	if !smc.timer.Stop() {
		select {
		case <-smc.timer.C:
		default:
		}
	}

	smc.timer.Reset(smc.timeout)
}