Skip to content

Commit 10f7abb

Browse files
Merge pull request #757 from dignifiedquire/feat/smol
2 parents 370642e + 27c605b commit 10f7abb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+842
-1619
lines changed

Diff for: .github/workflows/ci.yml

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ jobs:
5858
with:
5959
command: check
6060
args: --features unstable --all --bins --examples --tests
61+
62+
- name: check wasm
63+
uses: actions-rs/cargo@v1
64+
with:
65+
command: check
66+
target: wasm32-unknown-unknown
67+
override: true
68+
args: --features unstable --all --bins --tests
6169

6270
- name: check bench
6371
uses: actions-rs/cargo@v1

Diff for: Cargo.toml

+19-14
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "1.5.0"
44
authors = [
55
"Stjepan Glavina <[email protected]>",
66
"Yoshua Wuyts <[email protected]>",
7+
"Friedel Ziegelmayer <[email protected]>",
78
"Contributors to async-std",
89
]
910
edition = "2018"
@@ -24,19 +25,13 @@ rustdoc-args = ["--cfg", "feature=\"docs\""]
2425
default = [
2526
"std",
2627
"async-task",
27-
"crossbeam-channel",
28-
"crossbeam-deque",
29-
"crossbeam-queue",
30-
"futures-timer",
3128
"kv-log-macro",
3229
"log",
33-
"mio",
34-
"mio-uds",
3530
"num_cpus",
3631
"pin-project-lite",
3732
]
3833
docs = ["attributes", "unstable", "default"]
39-
unstable = ["std", "broadcaster", "futures-timer"]
34+
unstable = ["std", "broadcaster"]
4035
attributes = ["async-attributes"]
4136
std = [
4237
"alloc",
@@ -47,6 +42,10 @@ std = [
4742
"once_cell",
4843
"pin-utils",
4944
"slab",
45+
"smol",
46+
"wasm-timer",
47+
"wasm-bindgen-futures",
48+
"futures-channel",
5049
]
5150
alloc = [
5251
"futures-core/alloc",
@@ -55,32 +54,38 @@ alloc = [
5554

5655
[dependencies]
5756
async-attributes = { version = "1.1.1", optional = true }
58-
async-task = { version = "1.3.1", optional = true }
57+
async-task = { version = "3.0.0", optional = true }
5958
broadcaster = { version = "1.0.0", optional = true }
60-
crossbeam-channel = { version = "0.4.2", optional = true }
61-
crossbeam-deque = { version = "0.7.3", optional = true }
62-
crossbeam-queue = { version = "0.2.0", optional = true }
6359
crossbeam-utils = { version = "0.7.2", optional = true }
6460
futures-core = { version = "0.3.4", optional = true, default-features = false }
6561
futures-io = { version = "0.3.4", optional = true }
66-
futures-timer = { version = "3.0.2", optional = true }
6762
kv-log-macro = { version = "1.0.4", optional = true }
6863
log = { version = "0.4.8", features = ["kv_unstable"], optional = true }
6964
memchr = { version = "2.3.3", optional = true }
70-
mio = { version = "0.6.19", optional = true }
71-
mio-uds = { version = "0.6.7", optional = true }
7265
num_cpus = { version = "1.12.0", optional = true }
7366
once_cell = { version = "1.3.1", optional = true }
7467
pin-project-lite = { version = "0.1.4", optional = true }
7568
pin-utils = { version = "0.1.0-alpha.4", optional = true }
7669
slab = { version = "0.4.2", optional = true }
7770

71+
[target.'cfg(not(target_os = "unknown"))'.dependencies]
72+
smol = { version = "0.1.1", optional = true }
73+
74+
[target.'cfg(target_arch = "wasm32")'.dependencies]
75+
wasm-timer = { version = "0.2.4", optional = true }
76+
wasm-bindgen-futures = { version = "0.4.10", optional = true }
77+
futures-channel = { version = "0.3.4", optional = true }
78+
79+
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
80+
wasm-bindgen-test = "0.3.10"
81+
7882
[dev-dependencies]
7983
femme = "1.3.0"
8084
rand = "0.7.3"
8185
surf = "1.0.3"
8286
tempdir = "0.3.7"
8387
futures = "0.3.4"
88+
rand_xorshift = "0.2.0"
8489

8590
[[test]]
8691
name = "stream"

Diff for: src/future/future/delay.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ use std::future::Future;
22
use std::pin::Pin;
33
use std::time::Duration;
44

5-
use futures_timer::Delay;
65
use pin_project_lite::pin_project;
76

87
use crate::task::{Context, Poll};
8+
use crate::utils::Timer;
99

1010
pin_project! {
1111
#[doc(hidden)]
@@ -14,13 +14,13 @@ pin_project! {
1414
#[pin]
1515
future: F,
1616
#[pin]
17-
delay: Delay,
17+
delay: Timer,
1818
}
1919
}
2020

2121
impl<F> DelayFuture<F> {
2222
pub fn new(future: F, dur: Duration) -> DelayFuture<F> {
23-
let delay = Delay::new(dur);
23+
let delay = Timer::after(dur);
2424

2525
DelayFuture { future, delay }
2626
}

Diff for: src/future/timeout.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use std::error::Error;
22
use std::fmt;
3+
use std::future::Future;
34
use std::pin::Pin;
45
use std::time::Duration;
5-
use std::future::Future;
66

7-
use futures_timer::Delay;
87
use pin_project_lite::pin_project;
98

109
use crate::task::{Context, Poll};
10+
use crate::utils::Timer;
1111

1212
/// Awaits a future or times out after a duration of time.
1313
///
@@ -33,11 +33,7 @@ pub async fn timeout<F, T>(dur: Duration, f: F) -> Result<T, TimeoutError>
3333
where
3434
F: Future<Output = T>,
3535
{
36-
let f = TimeoutFuture {
37-
future: f,
38-
delay: Delay::new(dur),
39-
};
40-
f.await
36+
TimeoutFuture::new(f, dur).await
4137
}
4238

4339
pin_project! {
@@ -46,14 +42,17 @@ pin_project! {
4642
#[pin]
4743
future: F,
4844
#[pin]
49-
delay: Delay,
45+
delay: Timer,
5046
}
5147
}
5248

5349
impl<F> TimeoutFuture<F> {
5450
#[allow(dead_code)]
5551
pub(super) fn new(future: F, dur: Duration) -> TimeoutFuture<F> {
56-
TimeoutFuture { future: future, delay: Delay::new(dur) }
52+
TimeoutFuture {
53+
future,
54+
delay: Timer::after(dur),
55+
}
5756
}
5857
}
5958

Diff for: src/io/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -307,22 +307,33 @@ cfg_std! {
307307
cfg_default! {
308308
// For use in the print macros.
309309
#[doc(hidden)]
310+
#[cfg(not(target_os = "unknown"))]
310311
pub use stdio::{_eprint, _print};
311312

313+
#[cfg(not(target_os = "unknown"))]
312314
pub use stderr::{stderr, Stderr};
315+
#[cfg(not(target_os = "unknown"))]
313316
pub use stdin::{stdin, Stdin};
317+
#[cfg(not(target_os = "unknown"))]
314318
pub use stdout::{stdout, Stdout};
315319
pub use timeout::timeout;
316320

317321
mod timeout;
322+
#[cfg(not(target_os = "unknown"))]
318323
mod stderr;
324+
#[cfg(not(target_os = "unknown"))]
319325
mod stdin;
326+
#[cfg(not(target_os = "unknown"))]
320327
mod stdio;
328+
#[cfg(not(target_os = "unknown"))]
321329
mod stdout;
322330
}
323331

324332
cfg_unstable_default! {
333+
#[cfg(not(target_os = "unknown"))]
325334
pub use stderr::StderrLock;
335+
#[cfg(not(target_os = "unknown"))]
326336
pub use stdin::StdinLock;
337+
#[cfg(not(target_os = "unknown"))]
327338
pub use stdout::StdoutLock;
328339
}

Diff for: src/io/read/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ use std::mem;
1717

1818
use crate::io::IoSliceMut;
1919

20-
pub use take::Take;
2120
pub use bytes::Bytes;
2221
pub use chain::Chain;
22+
pub use take::Take;
2323

2424
extension_trait! {
2525
use std::pin::Pin;
@@ -477,13 +477,13 @@ unsafe fn initialize<R: futures_io::AsyncRead>(_reader: &R, buf: &mut [u8]) {
477477
std::ptr::write_bytes(buf.as_mut_ptr(), 0, buf.len())
478478
}
479479

480-
#[cfg(test)]
480+
#[cfg(all(test, not(target_os = "unknown")))]
481481
mod tests {
482482
use crate::io;
483483
use crate::prelude::*;
484484

485485
#[test]
486-
fn test_read_by_ref() -> io::Result<()> {
486+
fn test_read_by_ref() {
487487
crate::task::block_on(async {
488488
let mut f = io::Cursor::new(vec![0u8, 1, 2, 3, 4, 5, 6, 7, 8]);
489489
let mut buffer = Vec::new();
@@ -493,14 +493,13 @@ mod tests {
493493
let reference = f.by_ref();
494494

495495
// read at most 5 bytes
496-
assert_eq!(reference.take(5).read_to_end(&mut buffer).await?, 5);
496+
assert_eq!(reference.take(5).read_to_end(&mut buffer).await.unwrap(), 5);
497497
assert_eq!(&buffer, &[0, 1, 2, 3, 4])
498498
} // drop our &mut reference so we can use f again
499499

500500
// original file still usable, read the rest
501-
assert_eq!(f.read_to_end(&mut other_buffer).await?, 4);
501+
assert_eq!(f.read_to_end(&mut other_buffer).await.unwrap(), 4);
502502
assert_eq!(&other_buffer, &[5, 6, 7, 8]);
503-
Ok(())
504-
})
503+
});
505504
}
506505
}

Diff for: src/io/read/take.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ impl<T: BufRead> BufRead for Take<T> {
218218
}
219219
}
220220

221-
#[cfg(test)]
221+
#[cfg(all(test, not(target_os = "unknown")))]
222222
mod tests {
223223
use crate::io;
224224
use crate::prelude::*;

Diff for: src/io/timeout.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
use std::future::Future;
12
use std::pin::Pin;
23
use std::task::{Context, Poll};
34
use std::time::Duration;
4-
use std::future::Future;
55

6-
use futures_timer::Delay;
76
use pin_project_lite::pin_project;
87

98
use crate::io;
9+
use crate::utils::Timer;
1010

1111
/// Awaits an I/O future or times out after a duration of time.
1212
///
@@ -37,7 +37,7 @@ where
3737
F: Future<Output = io::Result<T>>,
3838
{
3939
Timeout {
40-
timeout: Delay::new(dur),
40+
timeout: Timer::after(dur),
4141
future: f,
4242
}
4343
.await
@@ -53,7 +53,7 @@ pin_project! {
5353
#[pin]
5454
future: F,
5555
#[pin]
56-
timeout: Delay,
56+
timeout: Timer,
5757
}
5858
}
5959

Diff for: src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,17 @@ cfg_std! {
267267
}
268268

269269
cfg_default! {
270+
#[cfg(not(target_os = "unknown"))]
270271
pub mod fs;
271272
pub mod path;
272273
pub mod net;
274+
#[cfg(not(target_os = "unknown"))]
273275
pub(crate) mod rt;
274276
}
275277

276278
cfg_unstable! {
277279
pub mod pin;
280+
#[cfg(not(target_os = "unknown"))]
278281
pub mod process;
279282

280283
mod unit;

Diff for: src/net/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,16 @@ pub use std::net::Shutdown;
6161
pub use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
6262
pub use std::net::{SocketAddr, SocketAddrV4, SocketAddrV6};
6363

64+
#[cfg(not(target_os = "unknown"))]
6465
pub use addr::ToSocketAddrs;
66+
#[cfg(not(target_os = "unknown"))]
6567
pub use tcp::{Incoming, TcpListener, TcpStream};
68+
#[cfg(not(target_os = "unknown"))]
6669
pub use udp::UdpSocket;
6770

71+
#[cfg(not(target_os = "unknown"))]
6872
mod addr;
73+
#[cfg(not(target_os = "unknown"))]
6974
mod tcp;
75+
#[cfg(not(target_os = "unknown"))]
7076
mod udp;

0 commit comments

Comments
 (0)