aws_sdk_emr/operation/list_steps/
paginator.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/// Paginator for [`ListSteps`](crate::operation::list_steps::ListSteps)
3pub struct ListStepsPaginator {
4    handle: std::sync::Arc<crate::client::Handle>,
5    builder: crate::operation::list_steps::builders::ListStepsInputBuilder,
6    stop_on_duplicate_token: bool,
7}
8
9impl ListStepsPaginator {
10    /// Create a new paginator-wrapper
11    pub(crate) fn new(handle: std::sync::Arc<crate::client::Handle>, builder: crate::operation::list_steps::builders::ListStepsInputBuilder) -> Self {
12        Self {
13            handle,
14            builder,
15            stop_on_duplicate_token: true,
16        }
17    }
18
19    /// Create a flattened paginator
20    ///
21    /// This paginator automatically flattens results using `steps`. Queries to the underlying service
22    /// are dispatched lazily.
23    pub fn items(self) -> crate::operation::list_steps::paginator::ListStepsPaginatorItems {
24        crate::operation::list_steps::paginator::ListStepsPaginatorItems(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_steps::ListStepsOutput,
48            ::aws_smithy_runtime_api::client::result::SdkError<
49                crate::operation::list_steps::ListStepsError,
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_steps::ListSteps::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_steps::ListSteps::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_steps_output_output_marker(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.marker.as_ref() && self.stop_on_duplicate_token {
86                                    true
87                                } else {
88                                    input.marker = 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}
107
108/// Flattened paginator for `ListStepsPaginator`
109///
110/// This is created with [`.items()`](ListStepsPaginator::items)
111pub struct ListStepsPaginatorItems(ListStepsPaginator);
112
113impl ListStepsPaginatorItems {
114    /// Create the pagination stream
115    ///
116    /// _Note_: No requests will be dispatched until the stream is used
117    /// (e.g. with the [`.next().await`](aws_smithy_async::future::pagination_stream::PaginationStream::next) method).
118    ///
119    /// To read the entirety of the paginator, use [`.collect::<Result<Vec<_>, _>()`](aws_smithy_async::future::pagination_stream::PaginationStream::collect).
120    pub fn send(
121        self,
122    ) -> ::aws_smithy_async::future::pagination_stream::PaginationStream<
123        ::std::result::Result<
124            crate::types::StepSummary,
125            ::aws_smithy_runtime_api::client::result::SdkError<
126                crate::operation::list_steps::ListStepsError,
127                ::aws_smithy_runtime_api::client::orchestrator::HttpResponse,
128            >,
129        >,
130    > {
131        ::aws_smithy_async::future::pagination_stream::TryFlatMap::new(self.0.send())
132            .flat_map(|page| crate::lens::lens_list_steps_output_output_steps(page).unwrap_or_default().into_iter())
133    }
134}