summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-11-02 21:23:04 +1100
committerJesse Duffield <jessedduffield@gmail.com>2021-11-05 07:58:21 +1100
commit308a3b51b39227e4d14d330a8c285bcf2a18ebc9 (patch)
tree78e1b7d2abb0a39b8e9a9c01e6f784b1c91a1153
parentccd80a0e4b87af6d9ada5895c2135736665a9387 (diff)
some more throttling stuff
-rw-r--r--pkg/tasks/tasks.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/pkg/tasks/tasks.go b/pkg/tasks/tasks.go
index 62237f22f..479006808 100644
--- a/pkg/tasks/tasks.go
+++ b/pkg/tasks/tasks.go
@@ -16,6 +16,9 @@ import (
const THROTTLE_TIME = time.Millisecond * 30
+// we use this to check if the system is under stress right now. Hopefully this makes sense on other machines
+const COMMAND_START_THRESHOLD = time.Millisecond * 10
+
type Task struct {
stop chan struct{}
stopped bool
@@ -91,12 +94,16 @@ func (m *ViewBufferManager) NewCmdTask(start func() (*exec.Cmd, io.Reader), pref
}
startTime := time.Now()
-
cmd, r := start()
+ timeToStart := time.Since(startTime)
go utils.Safe(func() {
<-stop
- m.throttle = time.Since(startTime) < THROTTLE_TIME
+ // we use the time it took to start the program as a way of checking if things
+ // are running slow at the moment. This is admittedly a crude estimate, but
+ // the point is that we only want to throttle when things are running slow
+ // and the user is flicking through a bunch of items.
+ m.throttle = time.Since(startTime) < THROTTLE_TIME && timeToStart > COMMAND_START_THRESHOLD
if err := oscommands.Kill(cmd); err != nil {
if !strings.Contains(err.Error(), "process already finished") {
m.Log.Errorf("error when running cmd task: %v", err)