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 */
67use aws_smithy_http::event_stream::{InitialMessageType, Receiver};
8use aws_smithy_runtime_api::client::result::SdkError;
9use aws_smithy_types::event_stream::{Message, RawMessage};
1011#[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}
1617impl<T, E> EventReceiver<T, E> {
18pub(crate) fn new(inner: Receiver<T, E>) -> Self {
19Self { inner }
20 }
2122#[allow(dead_code)]
23pub(crate) async fn try_recv_initial_request(&mut self) -> Result<Option<Message>, SdkError<E, RawMessage>> {
24self.inner.try_recv_initial(InitialMessageType::Request).await
25}
2627#[allow(dead_code)]
28pub(crate) async fn try_recv_initial_response(&mut self) -> Result<Option<Message>, SdkError<E, RawMessage>> {
29self.inner.try_recv_initial(InitialMessageType::Response).await
30}
3132/// 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.
36pub async fn recv(&mut self) -> Result<Option<T>, SdkError<E, RawMessage>> {
37self.inner.recv().await
38}
39}