prometheus-community / pro-bing

A library for creating continuous probers
MIT License
309 stars 52 forks source link

Return ctx.Err() from RunWithContext() and Run() #50

Closed floatingstatic closed 1 year ago

floatingstatic commented 1 year ago

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
    }