-
Notifications
You must be signed in to change notification settings - Fork 319
Description
Talking with @analogrelay about #3286, she had a good idea that would not only eliminate the need for the Mutex but also make the API safer such that with_continuation_token() only exists on the Pager (and eventually the Poller; see #2758) so you can't call it at the wrong time i.e., after the stream has started.
Like IntoFuture for Poller, we'd implement IntoStream for Pager (and Poller, for DX consistency). That would define continuation_token() but only the Pager itself would define with_continuation_token().
Additionally, because the Pager (rather, the ItemIterator; we should do the same for PageIterator as well for DX consistency) owns the continuation_token field and Option<String> should also be Send, we shouldn't have to lock it in a Mutex - just an Arc<Option<String>> should suffice.
The only downside is a change to require calling into_stream() since there's no desugaring it for now like there is for std::future::IntoFuture e.g.,
let mut pager = client.list_secrets(...).into_stream();
let cont_token = pager.continuation_token();
while let Some(item) = pager.try_next().await? {
println!("{item:#?}");
}
let mut pager = client.list_secrets(...).with_continuation_token(cont_token).into_stream();The desugaring for IntoStream (rather, IntoAsyncIterator) could come later, though. See rust-lang/rust#79024 and its RFC, https://github.com/rust-lang/rfcs/blob/master/text/2996-async-iterator.md.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status