RunWithContext() takes in a context and stops the pinger when the context is done, however it is difficult to capture the reason the context is closed.
It would be useful to do something like:
if err := pinger.RunWithContext(ctx); err != nil {
if !errors.Is(err, context.Canceled) {
// do something interesting only when context was not cancelled/closed
}
}
This is currently not possible and we have to do something like this outside of pinger.RunWithContext() to achieve something similar:
select {
case <-ctx.Done():
return
default:
// do something interesting only when context was not cancelled/closed/whatever
}
RunWithContext()
takes in a context and stops the pinger when the context is done, however it is difficult to capture the reason the context is closed. It would be useful to do something like:This is currently not possible and we have to do something like this outside of
pinger.RunWithContext()
to achieve something similar: