aws_sdk_elasticsearch/operation/describe_reserved_elasticsearch_instance_offerings/
paginator.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/// Paginator for [`DescribeReservedElasticsearchInstanceOfferings`](crate::operation::describe_reserved_elasticsearch_instance_offerings::DescribeReservedElasticsearchInstanceOfferings)
3pub struct DescribeReservedElasticsearchInstanceOfferingsPaginator {
4    handle: std::sync::Arc<crate::client::Handle>,
5    builder:
6        crate::operation::describe_reserved_elasticsearch_instance_offerings::builders::DescribeReservedElasticsearchInstanceOfferingsInputBuilder,
7    stop_on_duplicate_token: bool,
8}
9
10impl DescribeReservedElasticsearchInstanceOfferingsPaginator {
11    /// Create a new paginator-wrapper
12    pub(crate) fn new(
13        handle: std::sync::Arc<crate::client::Handle>,
14        builder: crate::operation::describe_reserved_elasticsearch_instance_offerings::builders::DescribeReservedElasticsearchInstanceOfferingsInputBuilder,
15    ) -> Self {
16        Self {
17            handle,
18            builder,
19            stop_on_duplicate_token: true,
20        }
21    }
22
23    /// Set the page size
24    ///
25    /// _Note: this method will override any previously set value for `max_results`_
26    pub fn page_size(mut self, limit: i32) -> Self {
27        self.builder.max_results = ::std::option::Option::Some(limit);
28        self
29    }
30
31    /// Stop paginating when the service returns the same pagination token twice in a row.
32    ///
33    /// Defaults to true.
34    ///
35    /// For certain operations, it may be useful to continue on duplicate token. For example,
36    /// if an operation is for tailing a log file in real-time, then continuing may be desired.
37    /// This option can be set to `false` to accommodate these use cases.
38    pub fn stop_on_duplicate_token(mut self, stop_on_duplicate_token: bool) -> Self {
39        self.stop_on_duplicate_token = stop_on_duplicate_token;
40        self
41    }
42
43    /// Create the pagination stream
44    ///
45    /// _Note:_ No requests will be dispatched until the stream is used
46    /// (e.g. with the [`.next().await`](aws_smithy_async::future::pagination_stream::PaginationStream::next) method).
47    pub fn send(
48        self,
49    ) -> ::aws_smithy_async::future::pagination_stream::PaginationStream<
50        ::std::result::Result<
51            crate::operation::describe_reserved_elasticsearch_instance_offerings::DescribeReservedElasticsearchInstanceOfferingsOutput,
52            ::aws_smithy_runtime_api::client::result::SdkError<
53                crate::operation::describe_reserved_elasticsearch_instance_offerings::DescribeReservedElasticsearchInstanceOfferingsError,
54                ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
55            >,
56        >,
57    > {
58        // Move individual fields out of self for the borrow checker
59        let builder = self.builder;
60        let handle = self.handle;
61        let runtime_plugins = crate::operation::describe_reserved_elasticsearch_instance_offerings::DescribeReservedElasticsearchInstanceOfferings::operation_runtime_plugins(
62                                handle.runtime_plugins.clone(),
63                                &handle.conf,
64                                ::std::option::Option::None,
65                            ).with_operation_plugin(crate::sdk_feature_tracker::paginator::PaginatorFeatureTrackerRuntimePlugin::new());
66        ::aws_smithy_async::future::pagination_stream::PaginationStream::new(::aws_smithy_async::future::pagination_stream::fn_stream::FnStream::new(
67            move |tx| {
68                ::std::boxed::Box::pin(async move {
69                    // Build the input for the first time. If required fields are missing, this is where we'll produce an early error.
70                    let mut input = match builder
71                        .build()
72                        .map_err(::aws_smithy_runtime_api::client::result::SdkError::construction_failure)
73                    {
74                        ::std::result::Result::Ok(input) => input,
75                        ::std::result::Result::Err(e) => {
76                            let _ = tx.send(::std::result::Result::Err(e)).await;
77                            return;
78                        }
79                    };
80                    loop {
81                        let resp = crate::operation::describe_reserved_elasticsearch_instance_offerings::DescribeReservedElasticsearchInstanceOfferings::orchestrate(&runtime_plugins, input.clone()).await;
82                        // If the input member is None or it was an error
83                        let done = match resp {
84                            ::std::result::Result::Ok(ref resp) => {
85                                let new_token =
86                                    crate::lens::reflens_describe_reserved_elasticsearch_instance_offerings_output_output_next_token(resp);
87                                // Pagination is exhausted when the next token is an empty string
88                                let is_empty = new_token.map(|token| token.is_empty()).unwrap_or(true);
89                                if !is_empty && new_token == input.next_token.as_ref() && self.stop_on_duplicate_token {
90                                    true
91                                } else {
92                                    input.next_token = new_token.cloned();
93                                    is_empty
94                                }
95                            }
96                            ::std::result::Result::Err(_) => true,
97                        };
98                        if tx.send(resp).await.is_err() {
99                            // receiving end was dropped
100                            return;
101                        }
102                        if done {
103                            return;
104                        }
105                    }
106                })
107            },
108        ))
109    }
110}