Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jun 24, 2023

Conversation

floatingstatic
Copy link
Contributor

@floatingstatic floatingstatic commented Jun 23, 2023

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
	}

Signed-off-by: Jeremiah Millay <jmillay@fastly.com>
Copy link
Contributor

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks

@SuperQ SuperQ merged commit 1530f0f into prometheus-community:main Jun 24, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants