aws_sdk_transcribestreaming/
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(
24        &mut self,
25    ) -> Result<Option<Message>, SdkError<E, RawMessage>> {
26        self.inner
27            .try_recv_initial(InitialMessageType::Request)
28            .await
29    }
30
31    #[allow(dead_code)]
32    pub(crate) async fn try_recv_initial_response(
33        &mut self,
34    ) -> Result<Option<Message>, SdkError<E, RawMessage>> {
35        self.inner
36            .try_recv_initial(InitialMessageType::Response)
37            .await
38    }
39
40    /// Asynchronously tries to receive an event from the stream. If the stream has ended, it
41    /// returns an `Ok(None)`. If there is a transport layer error, it will return
42    /// `Err(SdkError::DispatchFailure)`. Service-modeled errors will be a part of the returned
43    /// messages.
44    pub async fn recv(&mut self) -> Result<Option<T>, SdkError<E, RawMessage>> {
45        self.inner.recv().await
46    }
47}
48