sleep less if found something new

This commit is contained in:
yory8 2019-03-23 11:08:06 +01:00
parent cf9b496f25
commit 17ba2582a5

View file

@ -7,8 +7,6 @@ import (
"time" "time"
) )
const sleep = 1 * time.Second
func write(history []string, histfile string) error { func write(history []string, histfile string) error {
histlog, err := json.Marshal(history) histlog, err := json.Marshal(history)
if err != nil { if err != nil {
@ -52,7 +50,7 @@ func listen(history []string, histfile string) error {
text := string(t) text := string(t)
if err != nil || text == "" { if err != nil || text == "" {
// there's nothing to select, so we sleep. // there's nothing to select, so we sleep.
time.Sleep(sleep) time.Sleep(1 * time.Second)
continue continue
} }
@ -63,7 +61,7 @@ func listen(history []string, histfile string) error {
// wl-paste will always give back the last copied text // wl-paste will always give back the last copied text
// (as long as the place we copied from is still running) // (as long as the place we copied from is still running)
if history[l-1] == text { if history[l-1] == text {
time.Sleep(sleep) time.Sleep(1 * time.Second)
continue continue
} }
@ -87,7 +85,10 @@ func listen(history []string, histfile string) error {
return err return err
} }
time.Sleep(sleep) // writing to json is time consuming, so it's fine to sleep less and
// get ready to detect new events sooner.
// also because if we copied once, we might copy soon after.
time.Sleep(500 * time.Millisecond)
} }
} }