aws_sdk_sagemakergeospatial/operation/search_raster_data_collection/
paginator.rs

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