Skip to content

Replace genawaiter for async-stream #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 22 additions & 75 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lambda/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tower-service = "0.3"
bytes = "0.5"
http = "0.2"
lambda-attributes = { path = "../lambda-attributes", version = "0.1.0", optional = true}
genawaiter = { version = "0.99", features = ["futures03"] }
async-stream = "0.2"
futures = "0.3"
tracing = "0.1.13"
tracing-futures = "0.2.3"
Expand Down
13 changes: 7 additions & 6 deletions lambda/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
pub use crate::types::Context;
use client::Client;
use futures::stream::{Stream, StreamExt};
use genawaiter::{sync::gen, yield_};
pub use lambda_attributes::lambda;
use serde::{Deserialize, Serialize};
use std::{
Expand Down Expand Up @@ -179,17 +178,18 @@ where
}

fn incoming(client: &Client) -> impl Stream<Item = Result<http::Response<hyper::Body>, Error>> + '_ {
gen!({
async_stream::stream! {
loop {
let req = NextEventRequest.into_req().expect("Unable to construct request");
yield_!(client.call(req).await)
let res = client.call(req).await;
yield res;
}
})
}
}

async fn run_inner<A, B, F>(
client: &Client,
incoming: impl Stream<Item = Result<http::Response<hyper::Body>, Error>> + Unpin,
incoming: impl Stream<Item = Result<http::Response<hyper::Body>, Error>>,
handler: &mut F,
) -> Result<(), Error>
where
Expand All @@ -198,7 +198,8 @@ where
A: for<'de> Deserialize<'de>,
B: Serialize,
{
let mut incoming = incoming;
tokio::pin!(incoming);

while let Some(event) = incoming.next().await {
let event = event?;
let (parts, body) = event.into_parts();
Expand Down