From b82cd7fa5adae9d9350943320ebc35483e9fca8f Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 4 Jan 2023 17:09:48 +0100 Subject: [PATCH] refactor(common): Simplify wasm timeout implementation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … and remove an infinitely-recursive From impl in the process. --- crates/matrix-sdk-common/src/timeout.rs | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/crates/matrix-sdk-common/src/timeout.rs b/crates/matrix-sdk-common/src/timeout.rs index 7a4200314..594e160ac 100644 --- a/crates/matrix-sdk-common/src/timeout.rs +++ b/crates/matrix-sdk-common/src/timeout.rs @@ -18,12 +18,6 @@ impl fmt::Display for ElapsedError { impl Error for ElapsedError {} -impl From for ElapsedError { - fn from(io_error: std::io::Error) -> Self { - io_error.into() - } -} - /// Wait for `future` to be completed. `future` needs to return /// a `Result`. /// @@ -38,15 +32,8 @@ where #[cfg(target_arch = "wasm32")] { - let try_future = async { - let output = future.await; - - // Contrary to clippy's note, the qualification of the Result is necessary - #[allow(unused_qualifications)] - Result::::Ok(output) - }; - - try_future.timeout(duration).await + let try_future = async { Ok::(future.await) }; + try_future.timeout(duration).await.map_err(|_| ElapsedError(())) } }