breto

A status bar written in Go.
git clone git://git.swab.dev/breto.git
Log | Files | Refs | README | LICENSE

commit b58bdb7250fbc5280333f5589829f2fc935745ff
parent 484868bf696cf8b183394d28766e37785e889931
Author: Jaron Swab <jaron@swab.dev>
Date:   Tue, 20 Apr 2021 21:06:53 -0400

Moved mutex declaration out of loop

Diffstat:
Mmain.go | 6+++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/main.go b/main.go @@ -27,6 +27,7 @@ func main() { eRAM = make(chan error) cHomeDisk = make(chan string) eHomeDisk = make(chan error) + mutex = &sync.Mutex{} ) o := opt.ParseFlags() @@ -56,7 +57,6 @@ func main() { bat.FiveMins = math.Floor(math.Remainder(bat.Passed, 300)) } - var mutex = &sync.Mutex{} select { // updates the go routine channels as they send data case info.Weather = <-cWttr: case info.WttrErr = <-eWttr: @@ -85,6 +85,8 @@ func main() { func writeToLog(errMsg string, mutex *sync.Mutex) { mutex.Lock() + defer mutex.Unlock() + cache := os.Getenv("XDG_CACHE_HOME") if cache == "" { cache = "." @@ -95,8 +97,6 @@ func writeToLog(errMsg string, mutex *sync.Mutex) { if err != nil { log.Println(err) } - - defer mutex.Unlock() defer f.Close() logger := log.New(f, "prefix", log.LstdFlags)