From 612e4fbeb14001d5eef0bb0e3e19ea65eb47cef2 Mon Sep 17 00:00:00 2001 From: hhvn Date: Sun, 14 Apr 2024 13:49:18 +0100 Subject: Tidy up the status block api a bit Handle (nearly) all the plumbing (sleeps, goroutines and comms) in register() --- status/00-status.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'status/00-status.go') diff --git a/status/00-status.go b/status/00-status.go index dadc668..ca8282c 100644 --- a/status/00-status.go +++ b/status/00-status.go @@ -41,7 +41,7 @@ func init() { }() } -func register(name string, fn func(string) error) { +func register(name string, fn func(*Block) error, seconds int) { nid := 0 for _, id := range blockid { if id >= nid { @@ -53,22 +53,24 @@ func register(name string, fn func(string) error) { go func(){ for { - err := fn(name) + u := newBlock(name) + err := fn(u) if err != nil { common.Error("block \"%s\": %s\n", name, err) - u := newUpdate(name) u.drawText(0, config.Red, fmt.Sprintf("[err: %s]", name)) updates <- u - sleep(5) + } else { + updates <- u + sleep(seconds) } } }() } -func newUpdate(name string) (*Block) { +func newBlock(name string) (*Block) { var s Block s.Name = name -- cgit v1.2.3