diff --git a/crates/matrix-sdk-common/src/executor.rs b/crates/matrix-sdk-common/src/executor.rs index f0b994c56..a8eecb5cd 100644 --- a/crates/matrix-sdk-common/src/executor.rs +++ b/crates/matrix-sdk-common/src/executor.rs @@ -15,6 +15,8 @@ //! Abstraction over an executor so we can spawn tasks under WASM the same way //! we do usually. +#[cfg(target_arch = "wasm32")] +pub use std::convert::Infallible as JoinError; #[cfg(target_arch = "wasm32")] use std::{ future::Future, @@ -25,15 +27,14 @@ use std::{ #[cfg(target_arch = "wasm32")] use futures_util::{future::RemoteHandle, FutureExt}; #[cfg(not(target_arch = "wasm32"))] -pub use tokio::task::{spawn, JoinHandle}; +pub use tokio::task::{spawn, JoinError, JoinHandle}; #[cfg(target_arch = "wasm32")] pub fn spawn(future: F) -> JoinHandle where F: Future + 'static, { - let fut = future.unit_error(); - let (fut, handle) = fut.remote_handle(); + let (fut, handle) = future.remote_handle(); wasm_bindgen_futures::spawn_local(fut); JoinHandle { handle } @@ -42,14 +43,14 @@ where #[cfg(target_arch = "wasm32")] #[derive(Debug)] pub struct JoinHandle { - handle: RemoteHandle>, + handle: RemoteHandle, } #[cfg(target_arch = "wasm32")] impl Future for JoinHandle { - type Output = Result; + type Output = Result; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - Pin::new(&mut self.handle).poll(cx) + Pin::new(&mut self.handle).poll(cx).map(Ok) } }