Skip to content

Use the context provide to UsageWithContext public function #1837

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GustavoCaso
Copy link

@GustavoCaso GustavoCaso commented Apr 11, 2025

Currently, at work, we use gopsutil. We wanted to use the disk.UsageWithContext to allow setting some timeout when calling the Usage function.

We realized that the function UsageWithContext does not use the ctx provided.

It think would be a good addition to this great package.

That way, the user can do:

ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()

usage, err := UsageWithContext(ctx, "/")
if err != nil {
	log.Fatal(err)
}

Before adding a test or applying this pattern to other functions *WithContext, I wanted to know if we would be okay with having it in the package. If so, I can add tests and extend the pattern to the rest of the *WithContext functions.

Looking forward for your feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant