Skip to content

Commit efd4b7f

Browse files
authored
Merge branch 'master' into book-release-ready
2 parents 6585722 + 6418bc9 commit efd4b7f

File tree

15 files changed

+159
-196
lines changed

15 files changed

+159
-196
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Version 0.99.3
2+
3+
- Initial beta release

Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
[package]
22
name = "async-std"
3-
version = "0.1.0"
4-
authors = ["Stjepan Glavina <[email protected]>"]
3+
version = "0.99.3"
4+
authors = [
5+
"Stjepan Glavina <[email protected]>",
6+
"The async-std Project Developers",
7+
]
58
edition = "2018"
69
license = "Apache-2.0/MIT"
710
repository = "https://github.com/async-rs/async-std"
@@ -13,13 +16,13 @@ categories = ["asynchronous", "concurrency", "network-programming"]
1316

1417
[package.metadata.docs.rs]
1518
features = ["docs"]
16-
rustdoc-args = ["--features docs"]
19+
rustdoc-args = ["--cfg", "feature=\"docs\""]
1720

1821
[features]
1922
docs = []
2023

2124
[dependencies]
22-
async-task = { git = "ssh://[email protected]/async-rs/async-task.git" }
25+
async-task = "1.0.0"
2326
cfg-if = "0.1.9"
2427
crossbeam-channel = "0.3.9"
2528
futures-preview = "0.3.0-alpha.17"

README.md

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Async version of Rust's standard library
22

3-
[![Build Status](https://travis-ci.com/async-rs/async-std.svg?branch=master)](https://travis-ci.org/async-rs/async-std)
4-
[![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](
5-
https://github.com/async-rs/async-std)
3+
[![Build Status](https://travis-ci.com/async-rs/async-std.svg?branch=master)](https://travis-ci.com/async-rs/async-std)
4+
[![License](https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg)](https://github.com/async-rs/async-std)
65
[![Cargo](https://img.shields.io/crates/v/async-std.svg)](https://crates.io/crates/async-std)
76
[![Documentation](https://docs.rs/async-std/badge.svg)](https://docs.rs/async-std)
87
[![chat](https://img.shields.io/discord/598880689856970762.svg?logo=discord)](https://discord.gg/JvZeVNe)
98

10-
This crate provides an async version of [`std`]. It provides all the interfaces you are used to, but in an async version and ready for Rust's `async/await`-syntax.
9+
This crate provides an async version of [`std`]. It provides all the interfaces you
10+
are used to, but in an async version and ready for Rust's `async`/`await` syntax.
1111

1212
[`std`]: https://doc.rust-lang.org/std/index.html
1313

@@ -49,15 +49,51 @@ fn main() {
4949
}
5050
```
5151

52+
## Low-Friction Sockets with Built-In Timeouts
53+
54+
```rust
55+
#![feature(async_await)]
56+
57+
use std::time::Duration;
58+
59+
use async_std::{
60+
prelude::*,
61+
task,
62+
io,
63+
net::TcpStream,
64+
};
65+
66+
async fn get() -> io::Result<Vec<u8>> {
67+
let mut stream = TcpStream::connect("example.com:80").await?;
68+
stream.write_all(b"GET /index.html HTTP/1.0\r\n\r\n").await?;
69+
70+
let mut buf = vec![];
71+
72+
io::timeout(Duration::from_secs(5), async {
73+
stream.read_to_end(&mut buf).await?
74+
Ok(buf)
75+
})
76+
}
77+
78+
fn main() {
79+
task::block_on(async {
80+
let raw_response = get().await.expect("request");
81+
let response = String::from_utf8(raw_response)
82+
.expect("utf8 conversion");
83+
println!("received: {}", response);
84+
});
85+
}
86+
```
87+
5288
## Take a look around
5389

5490
Clone the repo:
5591

5692
```
57-
git clone [email protected]:stjepang/async-std.git && cd async-std
93+
git clone [email protected]:async-rs/async-std.git && cd async-std
5894
```
5995

60-
Read the docs:
96+
Generate docs:
6197

6298
```
6399
cargo doc --features docs.rs --open

docs/src/concepts/tasks.md

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,68 @@ For now, it is enough to know that once you `spawn`ed a task, it will continue r
6060
Tasks in `async_std` are one of the core abstractions. Much like Rust’s `thread`s, they provide some practical functionality over the raw concept. `Tasks` have a relationship to the runtime, but they are in themselves separate. `async_std` tasks have a number of desirable properties:
6161

6262

63-
- They are single-allocated
63+
- They are allocated in one single allocation
6464
- All tasks have a *backchannel*, which allows them to propagate results and errors to the spawning task through the `JoinHandle`
6565
- The carry desirable metadata for debugging
6666
- They support task local storage
6767

68-
`async_std` s task api handles setup and teardown of a backing runtime for you and doesn’t rely on a runtime being started.
68+
`async_std`s task api handles setup and teardown of a backing runtime for you and doesn’t rely on a runtime being started.
6969

7070
## Blocking
7171

72-
TODO: fill me in
72+
`Task`s are assumed to run _concurrently_, potentially by sharing a thread of execution. This means that operations blocking an _operating system thread_, such as `std::thread::sleep` or io function from Rusts stdlib will _stop execution of all tasks sharing this thread_. Other libraries (such as database drivers) have similar behaviour. Note that _blocking the current thread_ is not in and by itself bad behaviour, just something that does not mix well with they concurrent execution model of `async-std`. Essentially, never do this:
73+
74+
```rust
75+
fn main() {
76+
task::block_on(async {
77+
// this is std::fs, which blocks
78+
std::fs::read_to_string("test_file");
79+
})
80+
}
81+
```
82+
83+
If you want to mix operation kinds, consider putting such operations on a `thread`.
7384

7485
## Errors and panics
7586

76-
TODO: fill me in
87+
`Task`s report errors through normal channels: If they are fallible, their `Output` should be of kind `Result<T,E>`.
88+
89+
In case of `panic`, behaviour differs depending on if there's a reasonable part that addresses the `panic`. If not, the program _aborts_.
90+
91+
In practice, that means that `block_on` propagates panics to the blocking component:
92+
93+
```rust
94+
fn main() {
95+
task::block_on(async {
96+
panic!("test");
97+
});
98+
}
99+
```
100+
101+
```
102+
thread 'async-task-driver' panicked at 'test', examples/panic.rs:8:9
103+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
104+
```
105+
106+
While panicing a spawned tasks will abort:
107+
108+
```rust
109+
task::spawn(async {
110+
panic!("test");
111+
});
112+
113+
task::block_on(async {
114+
task::sleep(Duration::from_millis(10000)).await;
115+
})
116+
```
117+
118+
```
119+
thread 'async-task-driver' panicked at 'test', examples/panic.rs:8:9
120+
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
121+
Aborted (core dumped)
122+
```
77123

124+
That might seem odd at first, but the other option would be to silently ignore panics in spawned tasks. The current behaviour can be changed by catching panics in the spawned task and reacting with custom behaviour. This gives users the choice of panic handling strategy.
78125

79126
## Conclusion
80127

docs/src/security/policy.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22

33
Safety is one of the core principles of what we do, and to that end, we would like to ensure that async-std has a secure implementation. Thank you for taking the time to responsibly disclose any issues you find.
44

5-
All security bugs in async-std distribution should be reported by email to security@ferrous-systems.com. This list is delivered to a small security team. Your email will be acknowledged within 24 hours, and you’ll receive a more detailed response to your email within 48 hours indicating the next steps in handling your report. If you would like, you can encrypt your report using our public key. This key is also On MIT’s keyserver and reproduced below.
5+
All security bugs in async-std distribution should be reported by email to florian.gilcher@ferrous-systems.com. This list is delivered to a small security team. Your email will be acknowledged within 24 hours, and you’ll receive a more detailed response to your email within 48 hours indicating the next steps in handling your report. If you would like, you can encrypt your report using our public key. This key is also On MIT’s keyserver and reproduced below.
66

77
Be sure to use a descriptive subject line to avoid having your report be missed. After the initial reply to your report, the security team will endeavor to keep you informed of the progress being made towards a fix and full announcement. As recommended by [RFPolicy][rf-policy], these updates will be sent at least every five days. In reality, this is more likely to be every 24-48 hours.
88

99
If you have not received a reply to your email within 48 hours, or have not heard from the security team for the past five days, there are a few steps you can take (in order):
1010

11-
* Contact the current security coordinator TODO directly.
12-
* Contact the back-up contact TODO directly.
1311
* Post on our Community forums
1412

1513
Please note that the discussion forums are public areas. When escalating in these venues, please do not discuss your issue. Simply say that you’re trying to get a hold of someone from the security team.
@@ -34,4 +32,35 @@ This policy is adapted from the [Rust project](https://www.rust-lang.org/policie
3432

3533
## PGP Key
3634

37-
TODO
35+
```
36+
-----BEGIN PGP PUBLIC KEY BLOCK-----
37+
38+
mQENBF1Wu/ABCADJaGt4HwSlqKB9BGHWYKZj/6mTMbmc29vsEOcCSQKo6myCf9zc
39+
sasWAttep4FAUDX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+
v2fWCheTrHP3wfBAt5zyDet7IZd/EhYAK6xXEwr9nBPjfbaVexm2B8K6hOPNj0Bp
56+
OKm4rcOj7JYlcxrwhMvNnwEue7MqH1oXAsoaC1BW+qs4acp/hHpesweL6Rcg1pED
57+
OJUQd3UvRsqRK0EsorDu0oj5wt6Qp3ZEbPMAEQEAAYkBHwQYAQIACQUCXVa78AIb
58+
DAAKCRAAl2Pez8C7Uv8bB/9scRm2wvzHLbFtcEHaHvlKO1yYfSVqKqJzIKHc7pM2
59+
+szM8JVRTxAbzK5Xih9SB5xlekixxO2UCJI5DkJ/ir/RCcg+/CAQ8iLm2UcYAgJD
60+
TocKiR5gjNAvUDI4tMrDLLdF+7+RCQGc7HBSxFiNBJVGAztGVh1+cQ0zaCX6Tt33
61+
1EQtyRcPID0m6+ip5tCJN0dILC0YcwzXGrSgjB03JqItIyJEucdQz6UB84TIAGku
62+
JJl4tktgD9T7Rb5uzRhHCSbLy89DQVvCcKD4B94ffuDW3HO8n8utDusOiZuG4BUf
63+
WdFy6/gTLNiFbTzkq1BBJQMN1nBwGs1sn63RRgjumZ1N
64+
=dIcF
65+
-----END PGP PUBLIC KEY BLOCK-----
66+
```

examples/stdin-timeout.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ use async_std::io;
88
use async_std::task;
99

1010
fn main() -> io::Result<()> {
11+
// This async scope times out after 5 seconds.
1112
task::block_on(io::timeout(Duration::from_secs(5), async {
1213
let stdin = io::stdin();
1314

15+
// Read a line from the standard input and display it.
1416
let mut line = String::new();
1517
stdin.read_line(&mut line).await?;
18+
dbg!(line);
1619

17-
print!("Got line: {}", line);
1820
Ok(())
1921
}))
2022
}

src/future/pending.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
/// use std::time::Duration;
99
///
1010
/// use async_std::future::pending;
11-
/// use async_std::prelude::*;
11+
/// use async_std::io;
1212
///
1313
/// let dur = Duration::from_secs(1);
14-
/// assert!(pending::<()>().timeout(dur).await.is_err());
14+
/// let fut = pending();
15+
///
16+
/// let res: io::Result<()> = io::timeout(dur, fut).await;
17+
/// assert!(res.is_err());
1518
/// #
1619
/// # }) }
1720
/// ```

src/future/ready.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
/// # #![feature(async_await)]
1111
/// # fn main() { async_std::task::block_on(async {
1212
/// #
13-
/// use async_std::future::ready;
13+
/// use async_std::future;
1414
///
15-
/// assert_eq!(ready(10).await, 10);
15+
/// assert_eq!(future::ready(10).await, 10);
1616
/// #
1717
/// # }) }
1818
/// ```

src/io/empty.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ impl AsyncRead for Empty {
6262

6363
impl AsyncBufRead for Empty {
6464
#[inline]
65-
fn poll_fill_buf(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
65+
fn poll_fill_buf<'a>(
66+
self: Pin<&'a mut Self>,
67+
_: &mut Context<'_>,
68+
) -> Poll<io::Result<&'a [u8]>> {
6669
Poll::Ready(Ok(&[]))
6770
}
6871

src/io/timeout.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::task::{Context, Poll};
2424
/// let stdin = io::stdin();
2525
/// let mut line = String::new();
2626
/// let n = stdin.read_line(&mut line).await?;
27+
/// Ok(())
2728
/// })
2829
/// .await?;
2930
/// #

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Async version of the Rust standard library.
22
//!
33
//! This crate is an async version of [`std`].
4+
//!
45
//! Higher-level documentation in the form of the book
56
//! ["Async programming in Rust with async-std"][book]
67
//! is available.
@@ -22,6 +23,9 @@
2223
//! })
2324
//! }
2425
//! ```
26+
//!
27+
//! See [here](https://github.com/async-rs/async-std/tree/master/examples)
28+
//! for more examples.
2529
2630
#![feature(async_await)]
2731
#![cfg_attr(feature = "docs", feature(doc_cfg))]
@@ -39,6 +43,5 @@ pub mod prelude;
3943
pub mod stream;
4044
pub mod sync;
4145
pub mod task;
42-
pub mod time;
4346

4447
pub(crate) mod utils;

src/prelude.rs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,6 @@
11
//! The async prelude.
22
//!
3-
//! The prelude re-exports the most commonly used traits in async programming.
4-
//!
5-
//! # Examples
6-
//!
7-
//! Import the prelude to use the [`timeout`] combinator:
8-
//!
9-
//! ```no_run
10-
//! # #![feature(async_await)]
11-
//! # fn main() -> std::io::Result<()> { async_std::task::block_on(async {
12-
//! #
13-
//! use std::time::Duration;
14-
//!
15-
//! use async_std::io;
16-
//! use async_std::prelude::*;
17-
//!
18-
//! let stdin = io::stdin();
19-
//! let mut line = String::new();
20-
//! let dur = Duration::from_secs(5);
21-
//!
22-
//! stdin.read_line(&mut line).timeout(dur).await??;
23-
//! #
24-
//! # Ok(()) }) }
25-
//! ```
26-
//!
27-
//! [`timeout`]: ../time/trait.Timeout.html#method.timeout
3+
//! The prelude re-exports the most commonly used traits in this crate.
284
295
#[doc(no_inline)]
306
pub use crate::future::Future;
@@ -40,5 +16,3 @@ pub use crate::io::Write as _;
4016
pub use crate::stream::Stream;
4117
#[doc(no_inline)]
4218
pub use crate::task_local;
43-
#[doc(no_inline)]
44-
pub use crate::time::Timeout as _;

src/task/sleep.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::time::Duration;
22

3-
use futures::future;
4-
5-
use crate::time::Timeout;
3+
use crate::future;
4+
use crate::io;
65

76
/// Sleeps for the specified amount of time.
87
///
@@ -27,5 +26,5 @@ use crate::time::Timeout;
2726
/// # }) }
2827
/// ```
2928
pub async fn sleep(dur: Duration) {
30-
let _ = future::pending::<()>().timeout(dur).await;
29+
let _: io::Result<()> = io::timeout(dur, future::pending()).await;
3130
}

0 commit comments

Comments
 (0)