Add concurrency

This commit is contained in:
dwrz
2026-10-27 12:41:06 +00:00
commit 2334f4eaf0
31 changed files with 43061 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
package main
import (
"fmt"
"time"
)
const (
title = "TOP TEN ZIP CODES BY HIGHEST CURRENT TEMPERATURE"
)
func display(ztchan chan []*ZipTemp, done chan struct{}) {
for {
locations, more := <-ztchan
if !more {
done <- struct{}{}
return
}
// Clear the screen.
print("\033[H\033[2J")
// Print the title and top ten.
fmt.Println(title)
fmt.Printf(
"Last update: %s.\n\n",
time.Now().Format(time.RFC1123),
)
for i, zt := range locations {
if zt == nil {
fmt.Printf("%d. No data\n", i+1)
continue
}
fmt.Printf(
"%d. %.02f°F %s (%s, %s)\n",
i+1,
zt.Temperature,
zt.ZipCode,
zt.City,
zt.State,
)
}
}
}