diff --git a/Cargo.toml b/Cargo.toml index 109c7ad74..0c18ff457 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -80,10 +80,10 @@ futures-timer = { version = "3.0.2", optional = true } surf = { version = "1.0.3", optional = true } [target.'cfg(not(target_os = "unknown"))'.dependencies] -async-executor = { version = "0.1.2", features = ["async-io"], optional = true } -async-io = { version = "0.1.8", optional = true } -blocking = { version = "0.5.2", optional = true } -futures-lite = { version = "0.1.8", optional = true } +async-executor = { version = "1.0.0", optional = true } +async-io = { version = "1.0.1", optional = true } +blocking = { version = "1.0.0", optional = true } +futures-lite = { version = "1.0.0", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] futures-timer = { version = "3.0.2", optional = true, features = ["wasm-bindgen"] } diff --git a/src/net/tcp/listener.rs b/src/net/tcp/listener.rs index 8c87fc5f0..fc88cda56 100644 --- a/src/net/tcp/listener.rs +++ b/src/net/tcp/listener.rs @@ -75,8 +75,6 @@ impl TcpListener { /// /// [`local_addr`]: #method.local_addr pub async fn bind(addrs: A) -> io::Result { - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - let mut last_err = None; let addrs = addrs.to_socket_addrs().await?; @@ -202,8 +200,6 @@ impl<'a> Stream for Incoming<'a> { impl From for TcpListener { /// Converts a `std::net::TcpListener` into its asynchronous equivalent. fn from(listener: std::net::TcpListener) -> TcpListener { - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - TcpListener { watcher: Async::new(listener).expect("TcpListener is known to be good"), } diff --git a/src/net/tcp/stream.rs b/src/net/tcp/stream.rs index f7bd5c919..2e14806fb 100644 --- a/src/net/tcp/stream.rs +++ b/src/net/tcp/stream.rs @@ -71,8 +71,6 @@ impl TcpStream { /// # Ok(()) }) } /// ``` pub async fn connect(addrs: A) -> io::Result { - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - let mut last_err = None; let addrs = addrs.to_socket_addrs().await?; @@ -358,8 +356,6 @@ impl Write for &TcpStream { impl From for TcpStream { /// Converts a `std::net::TcpStream` into its asynchronous equivalent. fn from(stream: std::net::TcpStream) -> TcpStream { - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - TcpStream { watcher: Arc::new(Async::new(stream).expect("TcpStream is known to be good")), } diff --git a/src/net/udp/mod.rs b/src/net/udp/mod.rs index dd47e0582..00cfd298c 100644 --- a/src/net/udp/mod.rs +++ b/src/net/udp/mod.rs @@ -68,8 +68,6 @@ impl UdpSocket { /// # Ok(()) }) } /// ``` pub async fn bind(addrs: A) -> io::Result { - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - let mut last_err = None; let addrs = addrs.to_socket_addrs().await?; @@ -481,8 +479,6 @@ impl UdpSocket { impl From for UdpSocket { /// Converts a `std::net::UdpSocket` into its asynchronous equivalent. fn from(socket: std::net::UdpSocket) -> UdpSocket { - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - UdpSocket { watcher: Async::new(socket).expect("UdpSocket is known to be good"), } diff --git a/src/os/unix/net/datagram.rs b/src/os/unix/net/datagram.rs index 83ef9fe95..99a9e8d23 100644 --- a/src/os/unix/net/datagram.rs +++ b/src/os/unix/net/datagram.rs @@ -45,8 +45,6 @@ pub struct UnixDatagram { impl UnixDatagram { fn new(socket: StdUnixDatagram) -> UnixDatagram { - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - UnixDatagram { watcher: Async::new(socket).expect("UnixDatagram is known to be good"), } @@ -66,8 +64,6 @@ impl UnixDatagram { /// # Ok(()) }) } /// ``` pub async fn bind>(path: P) -> io::Result { - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - let path = path.as_ref().to_owned(); let socket = Async::::bind(path)?; Ok(UnixDatagram { watcher: socket }) @@ -309,8 +305,6 @@ impl fmt::Debug for UnixDatagram { impl From for UnixDatagram { /// Converts a `std::os::unix::net::UnixDatagram` into its asynchronous equivalent. fn from(datagram: StdUnixDatagram) -> UnixDatagram { - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - UnixDatagram { watcher: Async::new(datagram).expect("UnixDatagram is known to be good"), } @@ -325,8 +319,6 @@ impl AsRawFd for UnixDatagram { impl FromRawFd for UnixDatagram { unsafe fn from_raw_fd(fd: RawFd) -> UnixDatagram { - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - let raw = StdUnixDatagram::from_raw_fd(fd); let datagram = Async::::new(raw).expect("invalid file descriptor"); UnixDatagram { watcher: datagram } diff --git a/src/os/unix/net/listener.rs b/src/os/unix/net/listener.rs index 078b780d0..dc4c64c7a 100644 --- a/src/os/unix/net/listener.rs +++ b/src/os/unix/net/listener.rs @@ -68,8 +68,6 @@ impl UnixListener { /// # Ok(()) }) } /// ``` pub async fn bind>(path: P) -> io::Result { - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - let path = path.as_ref().to_owned(); let listener = Async::::bind(path)?; @@ -194,8 +192,6 @@ impl Stream for Incoming<'_> { impl From for UnixListener { /// Converts a `std::os::unix::net::UnixListener` into its asynchronous equivalent. fn from(listener: StdUnixListener) -> UnixListener { - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - UnixListener { watcher: Async::new(listener).expect("UnixListener is known to be good"), } diff --git a/src/os/unix/net/stream.rs b/src/os/unix/net/stream.rs index 3b2fe36f4..11cdb8e91 100644 --- a/src/os/unix/net/stream.rs +++ b/src/os/unix/net/stream.rs @@ -57,8 +57,6 @@ impl UnixStream { /// # Ok(()) }) } /// ``` pub async fn connect>(path: P) -> io::Result { - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - let path = path.as_ref().to_owned(); let stream = Arc::new(Async::::connect(path).await?); @@ -81,8 +79,6 @@ impl UnixStream { /// # Ok(()) }) } /// ``` pub fn pair() -> io::Result<(UnixStream, UnixStream)> { - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - let (a, b) = Async::::pair()?; let a = UnixStream { watcher: Arc::new(a), @@ -228,8 +224,6 @@ impl fmt::Debug for UnixStream { impl From for UnixStream { /// Converts a `std::os::unix::net::UnixStream` into its asynchronous equivalent. fn from(stream: StdUnixStream) -> UnixStream { - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - let stream = Async::new(stream).expect("UnixStream is known to be good"); UnixStream { watcher: Arc::new(stream), diff --git a/src/task/executor.rs b/src/task/executor.rs index d9caf0531..0f511d0f0 100644 --- a/src/task/executor.rs +++ b/src/task/executor.rs @@ -28,14 +28,14 @@ pub(crate) fn run(future: F) -> T where F: Future, { - EXECUTOR.with(|executor| enter(|| GLOBAL_EXECUTOR.enter(|| executor.borrow().run(future)))) + EXECUTOR.with(|executor| enter(|| async_io::block_on(executor.borrow().run(future)))) } pub(crate) fn run_global(future: F) -> T where F: Future, { - enter(|| GLOBAL_EXECUTOR.run(future)) + enter(|| async_io::block_on(GLOBAL_EXECUTOR.run(future))) } /// Enters the tokio context if the `tokio` feature is enabled. diff --git a/src/utils.rs b/src/utils.rs index f3299f636..528a7074e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -66,10 +66,7 @@ mod timer { #[cfg(any(feature = "unstable", feature = "default"))] pub(crate) fn timer_after(dur: std::time::Duration) -> timer::Timer { - #[cfg(all(not(target_os = "unknown"), feature = "default"))] - once_cell::sync::Lazy::force(&crate::rt::RUNTIME); - - Timer::new(dur) + Timer::after(dur) } #[cfg(any( @@ -84,7 +81,7 @@ mod timer { pub(crate) struct Timer(futures_timer::Delay); impl Timer { - pub(crate) fn new(dur: std::time::Duration) -> Self { + pub(crate) fn after(dur: std::time::Duration) -> Self { Timer(futures_timer::Delay::new(dur)) } }