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

[Feature Request] Per-Request Context Support #95

Open
Exca-DK opened this issue Sep 20, 2024 · 2 comments
Open

[Feature Request] Per-Request Context Support #95

Exca-DK opened this issue Sep 20, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@Exca-DK
Copy link

Exca-DK commented Sep 20, 2024

🚀 Feature Request Description

Enable passing a context for each client method, instead of relying on a global timeout for the entire client.

Motivation

Is your feature request related to a problem? Please describe you use case.
A global timeout for all requests isn’t flexible enough. Some requests only need a few seconds, while others may take much longer. I need to handle short-duration requests without blocking event loops, while also supporting longer ones when necessary.

Pitch

Describe the solution you would like
Solution: Follow Go’s standard pattern by adding a context.Context as the first argument for each method. This would allow us to remove the global timeout on the HTTP client, relying on the context to manage request durations. Use context.Background() when no specific context is needed.

Describe alternatives you've considered
None at the moment.

Are you willing to open a pull request?
Yes, I’m happy to implement this if the feature is accepted.

Additional context

None

@Exca-DK Exca-DK added the enhancement New feature or request label Sep 20, 2024
@Exca-DK Exca-DK changed the title [Feature Request] <Feature Title> [Feature Request] Per-Request Context Support Sep 20, 2024
@gregnazario
Copy link
Contributor

Interesting, do you have an example of this pattern?

As a relatively new Go developer, I don't have all the patterns down to be fully idiomatic.

@Exca-DK
Copy link
Author

Exca-DK commented Oct 1, 2024

Glad you found it interesting! Here are some official resources for understanding the context pattern in Go:
Go context package documentation
Go blog: Understanding context

You may also find this example useful for seeing the pattern in action with the AWS SDK for Go:
AWS SDK for Go: Context pattern example

For example, using http.NewRequestWithContext here enables the use of the provided ctx, allowing the user to directly manage the request lifecycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

2 participants