mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-25 01:38:02 +02:00
Nicer debug output of timers
This commit is contained in:
@@ -4,11 +4,33 @@ package loop
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"golang.org/x/exp/slices"
|
||||
|
||||
"kitty/tools/tty"
|
||||
)
|
||||
|
||||
var debugprintln = tty.DebugPrintln
|
||||
|
||||
func (self *timer) update_deadline(now time.Time) {
|
||||
self.deadline = now.Add(self.interval)
|
||||
}
|
||||
|
||||
func (self timer) String() string {
|
||||
funcname := "<nil>"
|
||||
if self.callback != nil {
|
||||
p := reflect.ValueOf(self.callback).Pointer()
|
||||
f := runtime.FuncForPC(p)
|
||||
if f != nil {
|
||||
funcname = f.Name()
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf("Timer(callback=%s, deadline=%s, repeats=%v)", funcname, self.deadline.Sub(time.Now()), self.repeats)
|
||||
}
|
||||
|
||||
func (self *Loop) add_timer(interval time.Duration, repeats bool, callback TimerCallback) (IdType, error) {
|
||||
if self.timers == nil {
|
||||
return 0, fmt.Errorf("Cannot add timers before starting the run loop, add them in OnInitialize instead")
|
||||
|
||||
Reference in New Issue
Block a user