-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Add iterators to unified resource cache #52103
base: master
Are you sure you want to change the base?
Conversation
124228e
to
ff4cc96
Compare
e2ce7c1
to
b43230f
Compare
This updates the UnifiedResourceCache with IterateResources as an alternative to IterateUnifiedResources. The new function returns an iterator instead of collecting and returning a page of results. While this API may not entirely replace the current one, it offers a better way for users that just want to iterate resources without collecting them. Additionally, a few helper methods were included for callers that might wish to only iterate one specific resource type. Internally the UnifiedResourceCache was refactored to use the same logic for all exposed iteration methods.
b43230f
to
3621abd
Compare
) | ||
// IterateWindowsDesktops iterates over all cached windows desktops starting from the provided key. | ||
func (c *UnifiedResourceCache) IterateWindowsDesktops(ctx context.Context, start string, order IterationOrder) iter.Seq2[types.WindowsDesktop, error] { | ||
return iterateUnifiedResourceCache(ctx, c, start, order, types.KindWindowsDesktop, func(desktop types.WindowsDesktop) types.WindowsDesktop { return desktop.Copy() }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why cant this copy func just be types.WindowsDesktop.Copy
like the other types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler won't allow that because of the return type
// Copy returns a copy of this dynamic Windows desktop
Copy() *DynamicWindowsDesktopV1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, guess i could have just tried myself :)
LGTM!
This updates the UnifiedResourceCache with IterateResources as an alternative to IterateUnifiedResources. The new function returns an iterator instead of collecting and returning a page of results. While this API may not entirely replace the current one, it offers a better way for users that just want to iterate resources without collecting them. Additionally, a few helper methods were included for callers that might wish to only iterate one specific resource type. Internally the UnifiedResourceCache was refactored to use the same logic for all exposed iteration methods.