shhh
parent
7d2b9764c3
commit
d7d888453b
13
main.go
13
main.go
|
|
@ -34,7 +34,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for alert := range alerts {
|
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)
|
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) {
|
func alertsAfter(ctx context.Context, dur time.Duration) (chan string, error) {
|
||||||
ch := make(chan string)
|
ch := make(chan string)
|
||||||
|
deadline := time.Now().Add(dur)
|
||||||
go func() {
|
go func() {
|
||||||
defer close(ch)
|
defer close(ch)
|
||||||
select {
|
for ctx.Err() == nil && time.Now().Before(deadline) {
|
||||||
case <-ctx.Done():
|
seconds := int(time.Until(deadline).Seconds())
|
||||||
case <-time.After(dur):
|
fmt.Printf("\r%v ", time.Duration(seconds)*time.Second)
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
case <-time.After(time.Second):
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ch <- "alerting after " + dur.String()
|
ch <- "alerting after " + dur.String()
|
||||||
}()
|
}()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue