main
Bel LaPointe 2025-05-14 09:13:16 -04:00
parent 7d2b9764c3
commit d7d888453b
1 changed files with 9 additions and 4 deletions

View File

@ -34,7 +34,7 @@ func main() {
}
for alert := range alerts {
if err := alertAt(ctx, *ntfy, time.Now(), alert, time.Now().Format("15:04")); err != nil {
if err := alertAt(ctx, *ntfy, time.Now(), alert, time.Now().Format("15:04")); err != nil && ctx.Err() == nil {
panic(err)
}
}
@ -53,11 +53,16 @@ func alerts(ctx context.Context, gcal bool, args []string) (chan string, error)
func alertsAfter(ctx context.Context, dur time.Duration) (chan string, error) {
ch := make(chan string)
deadline := time.Now().Add(dur)
go func() {
defer close(ch)
for ctx.Err() == nil && time.Now().Before(deadline) {
seconds := int(time.Until(deadline).Seconds())
fmt.Printf("\r%v ", time.Duration(seconds)*time.Second)
select {
case <-ctx.Done():
case <-time.After(dur):
case <-time.After(time.Second):
}
}
ch <- "alerting after " + dur.String()
}()