From fc3883d08e3ce9d04be39b1fc2867c21b973dbd7 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 27 Jul 2023 10:44:03 +0200 Subject: [PATCH] ffi: Remove async from a few functions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … to hopefully work around current issues. --- bindings/matrix-sdk-ffi/src/room.rs | 58 +++++++++++++---------------- 1 file changed, 26 insertions(+), 32 deletions(-) diff --git a/bindings/matrix-sdk-ffi/src/room.rs b/bindings/matrix-sdk-ffi/src/room.rs index b1b37e438..dbc092529 100644 --- a/bindings/matrix-sdk-ffi/src/room.rs +++ b/bindings/matrix-sdk-ffi/src/room.rs @@ -226,39 +226,36 @@ impl Room { }) } - pub async fn add_timeline_listener( + pub fn add_timeline_listener( self: Arc, listener: Box, ) -> RoomTimelineListenerResult { - RUNTIME - .spawn(async move { - let timeline = self - .timeline - .write() - .await - .get_or_insert_with(|| { - let timeline = RUNTIME.block_on(self.inner.timeline()); - Arc::new(timeline) - }) - .clone(); + RUNTIME.block_on(async move { + let timeline = self + .timeline + .write() + .await + .get_or_insert_with(|| { + let timeline = RUNTIME.block_on(self.inner.timeline()); + Arc::new(timeline) + }) + .clone(); - let (timeline_items, timeline_stream) = timeline.subscribe().await; + let (timeline_items, timeline_stream) = timeline.subscribe().await; - let timeline_stream = TaskHandle::new(RUNTIME.spawn(async move { - pin_mut!(timeline_stream); + let timeline_stream = TaskHandle::new(RUNTIME.spawn(async move { + pin_mut!(timeline_stream); - while let Some(diff) = timeline_stream.next().await { - listener.on_update(Arc::new(TimelineDiff::new(diff))); - } - })); - - RoomTimelineListenerResult { - items: timeline_items.into_iter().map(TimelineItem::from_arc).collect(), - items_stream: Arc::new(timeline_stream), + while let Some(diff) = timeline_stream.next().await { + listener.on_update(Arc::new(TimelineDiff::new(diff))); } - }) - .await - .unwrap() + })); + + RoomTimelineListenerResult { + items: timeline_items.into_iter().map(TimelineItem::from_arc).collect(), + items_stream: Arc::new(timeline_stream), + } + }) } pub fn subscribe_to_back_pagination_status( @@ -960,13 +957,10 @@ impl SendAttachmentJoinHandle { } } -#[uniffi::export(async_runtime = "tokio")] +#[uniffi::export] impl SendAttachmentJoinHandle { - pub async fn join(self: Arc) -> Result<(), RoomError> { - RUNTIME - .spawn(async move { (&mut *self.join_hdl.lock().await).await.unwrap() }) - .await - .unwrap() + pub fn join(self: Arc) -> Result<(), RoomError> { + RUNTIME.block_on(async move { (&mut *self.join_hdl.lock().await).await.unwrap() }) } pub fn cancel(&self) {