package card_pusher import ( "strconv" "time" ) type StatusLine struct { v int t *time.Timer d time.Duration o func(int) } func (s *StatusLine) String() string { return strconv.Itoa(s.v) } func (s *StatusLine) Set(v int) { s.v = v } func (s *StatusLine) Get() int { return s.v } func (s *StatusLine) AfterSet(v int) { if s.t != nil { s.t.Stop() } s.t = time.AfterFunc(s.d, func() { s.v = v if s.o != nil { s.o(v) } }) } func (s *StatusLine) SubEvent(handler func(int)) { s.o = handler } func DefaultStatusLine(v int) *StatusLine { return NewStatusLine(v, 500*time.Millisecond) } func NewStatusLine(v int, d time.Duration) *StatusLine { return &StatusLine{ v: v, d: d, } }