shhh
parent
7d2b9764c3
commit
d7d888453b
13
main.go
13
main.go
|
|
@ -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)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
case <-time.After(dur):
|
||||
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(time.Second):
|
||||
}
|
||||
}
|
||||
ch <- "alerting after " + dur.String()
|
||||
}()
|
||||
|
|
|
|||
Loading…
Reference in New Issue