diff options
| author | hhvn <dev@hhvn.uk> | 2024-04-14 13:49:18 +0100 |
|---|---|---|
| committer | hhvn <dev@hhvn.uk> | 2024-04-14 13:49:18 +0100 |
| commit | 612e4fbeb14001d5eef0bb0e3e19ea65eb47cef2 (patch) | |
| tree | c000b5997dabcfe424af25b694a6c05356c03622 /status/00-status.go | |
| parent | 75a34eb4b035963970c8415316c2b2bd6a81eea6 (diff) | |
Tidy up the status block api a bit
Handle (nearly) all the plumbing (sleeps, goroutines and comms) in register()
Diffstat (limited to 'status/00-status.go')
| -rw-r--r-- | status/00-status.go | 12 |
1 files changed, 7 insertions, 5 deletions
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 |