summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-01-08 22:07:04 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-01-08 22:07:04 +0900
commitf401c42f9c22de9df7a40ee31727ff0eab5dd30e (patch)
tree7a9185b36aaf461a6036de259bae2e014a62f4c4 /src
parentefec9acd6f655c7e63d6cda61486c961fdaed443 (diff)
downloadfzf-f401c42f9c22de9df7a40ee31727ff0eab5dd30e.tar.gz
Adjust initial coordinator delay
Diffstat (limited to 'src')
-rw-r--r--src/core.go10
-rw-r--r--src/util.go13
2 files changed, 20 insertions, 3 deletions
diff --git a/src/core.go b/src/core.go
index b6f08572..5a81efa3 100644
--- a/src/core.go
+++ b/src/core.go
@@ -7,7 +7,8 @@ import (
"time"
)
-const COORDINATOR_DELAY time.Duration = 100 * time.Millisecond
+const COORDINATOR_DELAY_MAX time.Duration = 100 * time.Millisecond
+const COORDINATOR_DELAY_STEP time.Duration = 10 * time.Millisecond
func initProcs() {
runtime.GOMAXPROCS(runtime.NumCPU())
@@ -151,8 +152,11 @@ func Run(options *Options) {
}
}
})
- if ticks > 3 && delay && reading {
- time.Sleep(COORDINATOR_DELAY)
+ if delay && reading {
+ dur := DurWithin(
+ time.Duration(ticks)*COORDINATOR_DELAY_STEP,
+ 0, COORDINATOR_DELAY_MAX)
+ time.Sleep(dur)
}
}
}
diff --git a/src/util.go b/src/util.go
index 2144e54e..cc8d4f5d 100644
--- a/src/util.go
+++ b/src/util.go
@@ -1,5 +1,7 @@
package fzf
+import "time"
+
func Max(first int, items ...int) int {
max := first
for _, item := range items {
@@ -19,3 +21,14 @@ func Min(first int, items ...int) int {
}
return min
}
+
+func DurWithin(
+ val time.Duration, min time.Duration, max time.Duration) time.Duration {
+ if val < min {
+ return min
+ }
+ if val > max {
+ return max
+ }
+ return val
+}