Sleep main and worker loops on idle

This commit is contained in:
Drew DeVault 2018-01-10 08:35:26 -05:00
parent b5d5e0dbed
commit 305446abfd
2 changed files with 8 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"time"
"git.sr.ht/~sircmpwn/aerc2/config" "git.sr.ht/~sircmpwn/aerc2/config"
"git.sr.ht/~sircmpwn/aerc2/worker" "git.sr.ht/~sircmpwn/aerc2/worker"
@ -28,10 +29,15 @@ func main() {
workers = append(workers, work) workers = append(workers, work)
} }
for { for {
activity := false
for _, worker := range workers { for _, worker := range workers {
if msg := worker.GetMessage(); msg != nil { if msg := worker.GetMessage(); msg != nil {
activity = true
fmt.Printf("<- %T\n", msg) fmt.Printf("<- %T\n", msg)
} }
} }
if !activity {
time.Sleep(100 * time.Millisecond)
}
} }
} }

View File

@ -4,6 +4,7 @@ import (
"git.sr.ht/~sircmpwn/aerc2/worker/types" "git.sr.ht/~sircmpwn/aerc2/worker/types"
"fmt" "fmt"
"time"
) )
type IMAPWorker struct { type IMAPWorker struct {
@ -52,7 +53,7 @@ func (w *IMAPWorker) Run() {
fmt.Printf("<= %T\n", msg) fmt.Printf("<= %T\n", msg)
w.handleMessage(msg) w.handleMessage(msg)
default: default:
// no-op time.Sleep(100 * time.Millisecond)
} }
} }
} }