diff --git a/crates/matrix-sdk-common/src/executor.rs b/crates/matrix-sdk-common/src/executor.rs index b1cb1a7bf13..e533d189fc4 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, @@ -23,12 +25,7 @@ use std::{ }; #[cfg(target_arch = "wasm32")] -pub use futures_util::future::Aborted as JoinError; -#[cfg(target_arch = "wasm32")] -use futures_util::{ - future::{AbortHandle, Abortable, RemoteHandle}, - FutureExt, -}; +use futures_util::{future::RemoteHandle, FutureExt}; #[cfg(not(target_arch = "wasm32"))] pub use tokio::task::{spawn, JoinError, JoinHandle}; @@ -37,31 +34,16 @@ pub fn spawn(future: F) -> JoinHandle where F: Future + 'static, { - let (future, remote_handle) = future.remote_handle(); - let (abort_handle, abort_registration) = AbortHandle::new_pair(); - let future = Abortable::new(future, abort_registration); - - wasm_bindgen_futures::spawn_local(async { - // Poll the future, and ignore the result (either it's `Ok(())`, or it's - // `Err(Aborted)`). - let _ = future.await; - }); + let (fut, handle) = future.remote_handle(); + wasm_bindgen_futures::spawn_local(fut); - JoinHandle { remote_handle, abort_handle } + JoinHandle { handle } } #[cfg(target_arch = "wasm32")] #[derive(Debug)] pub struct JoinHandle { - remote_handle: RemoteHandle, - abort_handle: AbortHandle, -} - -#[cfg(target_arch = "wasm32")] -impl JoinHandle { - pub fn abort(&self) { - self.abort_handle.abort(); - } + handle: RemoteHandle, } #[cfg(target_arch = "wasm32")] @@ -69,12 +51,7 @@ impl Future for JoinHandle { type Output = Result; fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - if self.abort_handle.is_aborted() { - // The future has been aborted. It is not possible to poll it again. - Poll::Ready(Err(JoinError)) - } else { - Pin::new(&mut self.remote_handle).poll(cx).map(Ok) - } + Pin::new(&mut self.handle).poll(cx).map(Ok) } }