don't init runtime threadpool unless necessary

Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
pull/866/head
Marc-Antoine Perennou 4 years ago
parent e4fb4b6128
commit e2f638496c

@ -75,8 +75,6 @@ impl TcpListener {
///
/// [`local_addr`]: #method.local_addr
pub async fn bind<A: ToSocketAddrs>(addrs: A) -> io::Result<TcpListener> {
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<std::net::TcpListener> 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"),
}

@ -71,8 +71,6 @@ impl TcpStream {
/// # Ok(()) }) }
/// ```
pub async fn connect<A: ToSocketAddrs>(addrs: A) -> io::Result<TcpStream> {
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<std::net::TcpStream> 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")),
}

@ -68,8 +68,6 @@ impl UdpSocket {
/// # Ok(()) }) }
/// ```
pub async fn bind<A: ToSocketAddrs>(addrs: A) -> io::Result<UdpSocket> {
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<std::net::UdpSocket> 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"),
}

@ -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<P: AsRef<Path>>(path: P) -> io::Result<UnixDatagram> {
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
let path = path.as_ref().to_owned();
let socket = Async::<StdUnixDatagram>::bind(path)?;
Ok(UnixDatagram { watcher: socket })
@ -309,8 +305,6 @@ impl fmt::Debug for UnixDatagram {
impl From<StdUnixDatagram> 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::<StdUnixDatagram>::new(raw).expect("invalid file descriptor");
UnixDatagram { watcher: datagram }

@ -68,8 +68,6 @@ impl UnixListener {
/// # Ok(()) }) }
/// ```
pub async fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixListener> {
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
let path = path.as_ref().to_owned();
let listener = Async::<StdUnixListener>::bind(path)?;
@ -194,8 +192,6 @@ impl Stream for Incoming<'_> {
impl From<StdUnixListener> 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"),
}

@ -57,8 +57,6 @@ impl UnixStream {
/// # Ok(()) }) }
/// ```
pub async fn connect<P: AsRef<Path>>(path: P) -> io::Result<UnixStream> {
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
let path = path.as_ref().to_owned();
let stream = Arc::new(Async::<StdUnixStream>::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::<StdUnixStream>::pair()?;
let a = UnixStream {
watcher: Arc::new(a),
@ -228,8 +224,6 @@ impl fmt::Debug for UnixStream {
impl From<StdUnixStream> 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),

@ -66,9 +66,6 @@ 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::after(dur)
}

Loading…
Cancel
Save