From 6d2ab03f565a53200cad6e1a397060739b78d5b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 31 Dec 2019 14:17:56 +0200 Subject: [PATCH] reqwesthttpsrc: Simplify code to block on futures --- gst-plugin-reqwest/src/reqwesthttpsrc.rs | 31 +----------------------- 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/gst-plugin-reqwest/src/reqwesthttpsrc.rs b/gst-plugin-reqwest/src/reqwesthttpsrc.rs index 244382ae..95bcad21 100644 --- a/gst-plugin-reqwest/src/reqwesthttpsrc.rs +++ b/gst-plugin-reqwest/src/reqwesthttpsrc.rs @@ -687,13 +687,7 @@ impl ReqwestHttpSrc { } }; - let res = match block_on(&*RUNTIME, future) { - Ok(res) => res, - Err(_) => Err(Some(gst_error_msg!( - gst::ResourceError::Read, - ["Join error"] - ))), - }; + let res = RUNTIME.enter(|| futures::executor::block_on(future)); /* Clear out the canceller */ let _ = self.canceller.lock().unwrap().take(); @@ -702,29 +696,6 @@ impl ReqwestHttpSrc { } } -// Until tokio 0.2.0-alpha.6 `Runtime::block_on()` didn't require a mutable reference -// to the runtime. Now it does and we need to work around that. -// See https://github.com/tokio-rs/tokio/issues/2042 -fn block_on( - runtime: &tokio::runtime::Runtime, - future: F, -) -> Result -where - F: Send + Future, - F::Output: Send + 'static, -{ - use futures::task::FutureObj; - use std::mem; - - let future = FutureObj::new(Box::pin(future)); - - // We make sure here to block until the future is completely handled before returning - let future = unsafe { mem::transmute::<_, FutureObj<'static, _>>(future) }; - - let join_handle = runtime.spawn(future); - futures::executor::block_on(join_handle) -} - impl ObjectImpl for ReqwestHttpSrc { glib_object_impl!();