-
Notifications
You must be signed in to change notification settings - Fork 318
Eliminating locking and improve safety with Pagers, Pollers #3372
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
base: main
Are you sure you want to change the base?
Conversation
|
This is a draft to get some earlier feedback. For now I only changed I'll likely copy the code to I'll also copy the implementation to |
|
I can't make this work. The previous |
|
Actually, if the type params are the source of "ugliness" and complexity, then the goal is to eliminate them. If I use fewer in the declaration, I think can limit it to So, it might mean that pub type Pager<P, F = JsonFormat, C = Url> = ItemIterator<Response<P, F>, C>;Cosmos uses a pub type FeedPager<P, F = JsonFormat, C = String> = ItemIterator<Response<P, F>, C>; |
analogrelay
left a comment
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.
This feels on-track to me. I have some comments that might allow us to reduce clone()s, but I'm not really worried about them.
I do think the C: AsRef<str> bound could be removed, or simplified to C: Debug (for tracing purposes). The Pager doesn't actually care that it's a string. It just flows it back and forth to the actual request function.
| let mut iter = self.iter; | ||
|
|
||
| // Start with the current page until after all items are iterated. | ||
| iter.continuation_token = self.continuation_token.clone(); |
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.
We should be able to move the continuation_token rather than cloning it, no?
| continuation_token: Option<String>, | ||
| next_token: Arc<Mutex<Option<String>>>, | ||
| iter: PageIterator<P, C>, | ||
| continuation_token: Option<C>, |
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.
Does this actually need to hold the continuation_token itself? Or could the continuation_token functions just call in to PageIterator to get the current value?
| continuation_token: Option<C>, | ||
| options: PagerOptions<'static, C>, |
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.
We could just hold the PagerOptions, and update the continuation token there, to avoid cloning. Or, pull the entire PagerOptions apart in the constructor and only store the things we need here.
| enum State<P, C: AsRef<str>> { | ||
| Init, | ||
| Pending(BoxedFuture<P, C>), | ||
| More(C), |
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.
We probably don't need to store a copy of the continuation on the State anymore. We can just pull it from the fields on PageIterator and pass &C in to the make_request func.
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, though you might hit issues because the make_request future is probably hanging on to it. This is probably fine then.
Resolves #3294