From f22c4d5c787dfcafe0b65c2794108176039c9429 Mon Sep 17 00:00:00 2001 From: Kitaiti Makoto Date: Thu, 5 May 2022 04:51:42 +0900 Subject: [PATCH] Await in consumer --- plume-common/src/activity_pub/mod.rs | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/plume-common/src/activity_pub/mod.rs b/plume-common/src/activity_pub/mod.rs index 69d40cd5..07a1b908 100644 --- a/plume-common/src/activity_pub/mod.rs +++ b/plume-common/src/activity_pub/mod.rs @@ -173,26 +173,28 @@ where ); let client = client.clone(); let tx = tx.clone(); - rt.spawn(async move { - let _ = tx.send( + let _ = tx.send( + rt.spawn( client .post(&inbox) .headers(headers.clone()) .body(body) - .send() - .await, - ); - }); + .send(), + ), + ); } while let Some(request) = rx.recv().await { let _ = request + .await .map(move |r| { - if r.status().is_success() { - debug!("Successfully sent activity to inbox ({})", &r.url()); - } else { - warn!("Error while sending to inbox ({} {:?})", &r.url(), &r) - } - debug!("Response: \"{:?}\"\n", r); + r.map(|r| { + if r.status().is_success() { + debug!("Successfully sent activity to inbox ({})", &r.url()); + } else { + warn!("Error while sending to inbox ({} {:?})", &r.url(), &r) + } + debug!("Response: \"{:?}\"\n", r); + }) }) .map_err(|e| warn!("Error while sending to inbox ({:?})", e)); }