aws_sdk_s3/
event_receiver.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2/*
3 *  Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 *  SPDX-License-Identifier: Apache-2.0
5 */
6
7use aws_smithy_http::event_stream::{InitialMessageType, Receiver};
8use aws_smithy_runtime_api::client::result::SdkError;
9use aws_smithy_types::event_stream::{Message, RawMessage};
10
11#[derive(Debug)]
12/// Receives unmarshalled events at a time out of an Event Stream.
13pub struct EventReceiver<T, E> {
14    inner: Receiver<T, E>,
15}
16
17impl<T, E> EventReceiver<T, E> {
18    pub(crate) fn new(inner: Receiver<T, E>) -> Self {
19        Self { inner }
20    }
21
22    #[allow(dead_code)]
23    pub(crate) async fn try_recv_initial_request(&mut self) -> Result<Option<Message>, SdkError<E, RawMessage>> {
24        self.inner.try_recv_initial(InitialMessageType::Request).await
25    }
26
27    #[allow(dead_code)]
28    pub(crate) async fn try_recv_initial_response(&mut self) -> Result<Option<Message>, SdkError<E, RawMessage>> {
29        self.inner.try_recv_initial(InitialMessageType::Response).await
30    }
31
32    /// Asynchronously tries to receive an event from the stream. If the stream has ended, it
33    /// returns an `Ok(None)`. If there is a transport layer error, it will return
34    /// `Err(SdkError::DispatchFailure)`. Service-modeled errors will be a part of the returned
35    /// messages.
36    pub async fn recv(&mut self) -> Result<Option<T>, SdkError<E, RawMessage>> {
37        self.inner.recv().await
38    }
39}