main
Bel LaPointe 2025-05-14 09:19:45 -04:00
parent 5f38a36027
commit d05789b36b
1 changed files with 10 additions and 4 deletions

14
main.go
View File

@ -58,10 +58,14 @@ func alerts(ctx context.Context, gcal bool, args []string) (chan string, error)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return alertsAfter(ctx, duration) msg := "alerting after " + duration.String()
if len(args) > 1 {
msg = fmt.Sprintf("%s (%s)", args[1], duration.String())
}
return alertsAfter(ctx, duration, msg)
} }
func alertsAfter(ctx context.Context, dur time.Duration) (chan string, error) { func alertsAfter(ctx context.Context, dur time.Duration, msg string) (chan string, error) {
ch := make(chan string) ch := make(chan string)
deadline := time.Now().Add(dur) deadline := time.Now().Add(dur)
go func() { go func() {
@ -74,8 +78,10 @@ func alertsAfter(ctx context.Context, dur time.Duration) (chan string, error) {
case <-time.After(time.Second): case <-time.After(time.Second):
} }
} }
fmt.Println() if ctx.Err() == nil {
ch <- "alerting after " + dur.String() fmt.Println(msg)
}
ch <- msg
}() }()
return ch, nil return ch, nil
} }