aws_sdk_codestarconnections/operation/list_hosts/
paginator.rs

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