Refactor to async closures.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -64,7 +64,7 @@ pub(crate) async fn get_backfill_route(
|
||||
.timeline
|
||||
.pdus_rev(None, &body.room_id, Some(from.saturating_add(1)))
|
||||
.try_take(limit)
|
||||
.try_filter_map(|(_, pdu)| async move {
|
||||
.try_filter_map(async |(_, pdu)| {
|
||||
Ok(services
|
||||
.rooms
|
||||
.state_accessor
|
||||
@@ -72,7 +72,7 @@ pub(crate) async fn get_backfill_route(
|
||||
.await
|
||||
.then_some(pdu))
|
||||
})
|
||||
.try_filter_map(|pdu| async move {
|
||||
.try_filter_map(async |pdu| {
|
||||
Ok(services
|
||||
.rooms
|
||||
.timeline
|
||||
|
||||
@@ -49,7 +49,7 @@ pub(crate) async fn get_event_authorization_route(
|
||||
.auth_chain
|
||||
.event_ids_iter(room_id, once(body.event_id.borrow()))
|
||||
.ready_filter_map(Result::ok)
|
||||
.filter_map(|id| async move {
|
||||
.filter_map(async |id| {
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
|
||||
@@ -45,7 +45,7 @@ pub(crate) async fn get_hierarchy_route(
|
||||
let (children, inaccessible_children) =
|
||||
get_parent_children_via(&room, suggested_only)
|
||||
.stream()
|
||||
.broad_filter_map(|(child, _via)| async move {
|
||||
.broad_filter_map(async |(child, _via)| {
|
||||
match services
|
||||
.rooms
|
||||
.spaces
|
||||
|
||||
@@ -158,10 +158,11 @@ async fn handle(
|
||||
let results: ResolvedMap = pdus
|
||||
.into_iter()
|
||||
.try_stream()
|
||||
.broad_and_then(|(room_id, pdus): (_, Vec<_>)| {
|
||||
handle_room(services, client, origin, started, room_id, pdus.into_iter())
|
||||
.map_ok(Vec::into_iter)
|
||||
.broad_and_then(async |(room_id, pdus): (_, Vec<_>)| {
|
||||
handle_room(services, client, origin, &started, room_id, pdus.into_iter())
|
||||
.map_ok(ResolvedMap::into_iter)
|
||||
.map_ok(IterStream::try_stream)
|
||||
.await
|
||||
})
|
||||
.try_flatten()
|
||||
.try_collect()
|
||||
@@ -180,28 +181,27 @@ async fn handle_room(
|
||||
services: &Services,
|
||||
_client: &IpAddr,
|
||||
origin: &ServerName,
|
||||
txn_start_time: Instant,
|
||||
room_id: OwnedRoomId,
|
||||
txn_start_time: &Instant,
|
||||
ref room_id: OwnedRoomId,
|
||||
pdus: impl Iterator<Item = Pdu> + Send,
|
||||
) -> Result<Vec<(OwnedEventId, Result)>> {
|
||||
) -> Result<ResolvedMap> {
|
||||
let _room_lock = services
|
||||
.rooms
|
||||
.event_handler
|
||||
.mutex_federation
|
||||
.lock(&room_id)
|
||||
.lock(room_id)
|
||||
.await;
|
||||
|
||||
let room_id = &room_id;
|
||||
pdus.try_stream()
|
||||
.and_then(|(_, event_id, value)| async move {
|
||||
.and_then(async |(room_id, event_id, value)| {
|
||||
services.server.check_running()?;
|
||||
let pdu_start_time = Instant::now();
|
||||
let result = services
|
||||
.rooms
|
||||
.event_handler
|
||||
.handle_incoming_pdu(origin, room_id, &event_id, value, true)
|
||||
.await
|
||||
.map(|_| ());
|
||||
.handle_incoming_pdu(origin, &room_id, &event_id, value, true)
|
||||
.map_ok(|_| ())
|
||||
.await;
|
||||
|
||||
debug!(
|
||||
pdu_elapsed = ?pdu_start_time.elapsed(),
|
||||
@@ -329,7 +329,7 @@ async fn handle_edu_receipt_room(
|
||||
.read
|
||||
.into_iter()
|
||||
.stream()
|
||||
.for_each_concurrent(automatic_width(), |(user_id, user_updates)| async move {
|
||||
.for_each_concurrent(automatic_width(), async |(user_id, user_updates)| {
|
||||
handle_edu_receipt_room_user(services, origin, room_id, &user_id, user_updates).await;
|
||||
})
|
||||
.await;
|
||||
@@ -368,7 +368,7 @@ async fn handle_edu_receipt_room_user(
|
||||
.event_ids
|
||||
.into_iter()
|
||||
.stream()
|
||||
.for_each_concurrent(automatic_width(), |event_id| async move {
|
||||
.for_each_concurrent(automatic_width(), async |event_id| {
|
||||
let user_data = [(user_id.to_owned(), data.clone())];
|
||||
let receipts = [(ReceiptType::Read, BTreeMap::from(user_data))];
|
||||
let content = [(event_id.clone(), BTreeMap::from(receipts))];
|
||||
|
||||
@@ -242,7 +242,7 @@ async fn create_join_event(
|
||||
.rooms
|
||||
.auth_chain
|
||||
.event_ids_iter(room_id, starting_events)
|
||||
.broad_and_then(|event_id| async move {
|
||||
.broad_and_then(async |event_id| {
|
||||
services
|
||||
.rooms
|
||||
.timeline
|
||||
|
||||
@@ -56,7 +56,7 @@ pub(crate) async fn get_room_state_route(
|
||||
.rooms
|
||||
.auth_chain
|
||||
.event_ids_iter(&body.room_id, once(body.event_id.borrow()))
|
||||
.and_then(|id| async move { services.rooms.timeline.get_pdu_json(&id).await })
|
||||
.and_then(async |id| services.rooms.timeline.get_pdu_json(&id).await)
|
||||
.and_then(|pdu| {
|
||||
services
|
||||
.sending
|
||||
|
||||
@@ -40,7 +40,7 @@ pub(crate) async fn get_devices_route(
|
||||
devices: services
|
||||
.users
|
||||
.all_devices_metadata(user_id)
|
||||
.filter_map(|metadata| async move {
|
||||
.filter_map(async |metadata| {
|
||||
let device_id = metadata.device_id.clone();
|
||||
let device_id_clone = device_id.clone();
|
||||
let device_id_string = device_id.as_str().to_owned();
|
||||
|
||||
Reference in New Issue
Block a user