Skip to content

Commit f731959

Browse files
Merge pull request #866 from Keruspe/smol04
2 parents 1aa148d + 15798bd commit f731959

File tree

9 files changed

+8
-41
lines changed

9 files changed

+8
-41
lines changed

Cargo.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ futures-timer = { version = "3.0.2", optional = true }
8080
surf = { version = "1.0.3", optional = true }
8181

8282
[target.'cfg(not(target_os = "unknown"))'.dependencies]
83-
async-executor = { version = "0.1.2", features = ["async-io"], optional = true }
84-
async-io = { version = "0.1.8", optional = true }
85-
blocking = { version = "0.5.2", optional = true }
86-
futures-lite = { version = "0.1.8", optional = true }
83+
async-executor = { version = "1.0.0", optional = true }
84+
async-io = { version = "1.0.1", optional = true }
85+
blocking = { version = "1.0.0", optional = true }
86+
futures-lite = { version = "1.0.0", optional = true }
8787

8888
[target.'cfg(target_arch = "wasm32")'.dependencies]
8989
futures-timer = { version = "3.0.2", optional = true, features = ["wasm-bindgen"] }

src/net/tcp/listener.rs

-4
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,6 @@ impl TcpListener {
7575
///
7676
/// [`local_addr`]: #method.local_addr
7777
pub async fn bind<A: ToSocketAddrs>(addrs: A) -> io::Result<TcpListener> {
78-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
79-
8078
let mut last_err = None;
8179
let addrs = addrs.to_socket_addrs().await?;
8280

@@ -202,8 +200,6 @@ impl<'a> Stream for Incoming<'a> {
202200
impl From<std::net::TcpListener> for TcpListener {
203201
/// Converts a `std::net::TcpListener` into its asynchronous equivalent.
204202
fn from(listener: std::net::TcpListener) -> TcpListener {
205-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
206-
207203
TcpListener {
208204
watcher: Async::new(listener).expect("TcpListener is known to be good"),
209205
}

src/net/tcp/stream.rs

-4
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ impl TcpStream {
7171
/// # Ok(()) }) }
7272
/// ```
7373
pub async fn connect<A: ToSocketAddrs>(addrs: A) -> io::Result<TcpStream> {
74-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
75-
7674
let mut last_err = None;
7775
let addrs = addrs.to_socket_addrs().await?;
7876

@@ -358,8 +356,6 @@ impl Write for &TcpStream {
358356
impl From<std::net::TcpStream> for TcpStream {
359357
/// Converts a `std::net::TcpStream` into its asynchronous equivalent.
360358
fn from(stream: std::net::TcpStream) -> TcpStream {
361-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
362-
363359
TcpStream {
364360
watcher: Arc::new(Async::new(stream).expect("TcpStream is known to be good")),
365361
}

src/net/udp/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ impl UdpSocket {
6868
/// # Ok(()) }) }
6969
/// ```
7070
pub async fn bind<A: ToSocketAddrs>(addrs: A) -> io::Result<UdpSocket> {
71-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
72-
7371
let mut last_err = None;
7472
let addrs = addrs.to_socket_addrs().await?;
7573

@@ -528,8 +526,6 @@ impl UdpSocket {
528526
impl From<std::net::UdpSocket> for UdpSocket {
529527
/// Converts a `std::net::UdpSocket` into its asynchronous equivalent.
530528
fn from(socket: std::net::UdpSocket) -> UdpSocket {
531-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
532-
533529
UdpSocket {
534530
watcher: Async::new(socket).expect("UdpSocket is known to be good"),
535531
}

src/os/unix/net/datagram.rs

-8
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ pub struct UnixDatagram {
4545

4646
impl UnixDatagram {
4747
fn new(socket: StdUnixDatagram) -> UnixDatagram {
48-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
49-
5048
UnixDatagram {
5149
watcher: Async::new(socket).expect("UnixDatagram is known to be good"),
5250
}
@@ -66,8 +64,6 @@ impl UnixDatagram {
6664
/// # Ok(()) }) }
6765
/// ```
6866
pub async fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixDatagram> {
69-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
70-
7167
let path = path.as_ref().to_owned();
7268
let socket = Async::<StdUnixDatagram>::bind(path)?;
7369
Ok(UnixDatagram { watcher: socket })
@@ -309,8 +305,6 @@ impl fmt::Debug for UnixDatagram {
309305
impl From<StdUnixDatagram> for UnixDatagram {
310306
/// Converts a `std::os::unix::net::UnixDatagram` into its asynchronous equivalent.
311307
fn from(datagram: StdUnixDatagram) -> UnixDatagram {
312-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
313-
314308
UnixDatagram {
315309
watcher: Async::new(datagram).expect("UnixDatagram is known to be good"),
316310
}
@@ -325,8 +319,6 @@ impl AsRawFd for UnixDatagram {
325319

326320
impl FromRawFd for UnixDatagram {
327321
unsafe fn from_raw_fd(fd: RawFd) -> UnixDatagram {
328-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
329-
330322
let raw = StdUnixDatagram::from_raw_fd(fd);
331323
let datagram = Async::<StdUnixDatagram>::new(raw).expect("invalid file descriptor");
332324
UnixDatagram { watcher: datagram }

src/os/unix/net/listener.rs

-4
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ impl UnixListener {
6868
/// # Ok(()) }) }
6969
/// ```
7070
pub async fn bind<P: AsRef<Path>>(path: P) -> io::Result<UnixListener> {
71-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
72-
7371
let path = path.as_ref().to_owned();
7472
let listener = Async::<StdUnixListener>::bind(path)?;
7573

@@ -194,8 +192,6 @@ impl Stream for Incoming<'_> {
194192
impl From<StdUnixListener> for UnixListener {
195193
/// Converts a `std::os::unix::net::UnixListener` into its asynchronous equivalent.
196194
fn from(listener: StdUnixListener) -> UnixListener {
197-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
198-
199195
UnixListener {
200196
watcher: Async::new(listener).expect("UnixListener is known to be good"),
201197
}

src/os/unix/net/stream.rs

-6
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ impl UnixStream {
5757
/// # Ok(()) }) }
5858
/// ```
5959
pub async fn connect<P: AsRef<Path>>(path: P) -> io::Result<UnixStream> {
60-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
61-
6260
let path = path.as_ref().to_owned();
6361
let stream = Arc::new(Async::<StdUnixStream>::connect(path).await?);
6462

@@ -81,8 +79,6 @@ impl UnixStream {
8179
/// # Ok(()) }) }
8280
/// ```
8381
pub fn pair() -> io::Result<(UnixStream, UnixStream)> {
84-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
85-
8682
let (a, b) = Async::<StdUnixStream>::pair()?;
8783
let a = UnixStream {
8884
watcher: Arc::new(a),
@@ -228,8 +224,6 @@ impl fmt::Debug for UnixStream {
228224
impl From<StdUnixStream> for UnixStream {
229225
/// Converts a `std::os::unix::net::UnixStream` into its asynchronous equivalent.
230226
fn from(stream: StdUnixStream) -> UnixStream {
231-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
232-
233227
let stream = Async::new(stream).expect("UnixStream is known to be good");
234228
UnixStream {
235229
watcher: Arc::new(stream),

src/task/executor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ pub(crate) fn run<F, T>(future: F) -> T
2828
where
2929
F: Future<Output = T>,
3030
{
31-
EXECUTOR.with(|executor| enter(|| GLOBAL_EXECUTOR.enter(|| executor.borrow().run(future))))
31+
EXECUTOR.with(|executor| enter(|| async_io::block_on(executor.borrow().run(future))))
3232
}
3333

3434
pub(crate) fn run_global<F, T>(future: F) -> T
3535
where
3636
F: Future<Output = T>,
3737
{
38-
enter(|| GLOBAL_EXECUTOR.run(future))
38+
enter(|| async_io::block_on(GLOBAL_EXECUTOR.run(future)))
3939
}
4040

4141
/// Enters the tokio context if the `tokio` feature is enabled.

src/utils.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ mod timer {
6666

6767
#[cfg(any(feature = "unstable", feature = "default"))]
6868
pub(crate) fn timer_after(dur: std::time::Duration) -> timer::Timer {
69-
#[cfg(all(not(target_os = "unknown"), feature = "default"))]
70-
once_cell::sync::Lazy::force(&crate::rt::RUNTIME);
71-
72-
Timer::new(dur)
69+
Timer::after(dur)
7370
}
7471

7572
#[cfg(any(
@@ -84,7 +81,7 @@ mod timer {
8481
pub(crate) struct Timer(futures_timer::Delay);
8582

8683
impl Timer {
87-
pub(crate) fn new(dur: std::time::Duration) -> Self {
84+
pub(crate) fn after(dur: std::time::Duration) -> Self {
8885
Timer(futures_timer::Delay::new(dur))
8986
}
9087
}

0 commit comments

Comments
 (0)