Skip to content

Commit 84f1d26

Browse files
authored
Merge pull request #110 from eminence/summary
Update SUMMARY.md and ignore code blocks in stories
2 parents 6b65c5a + 57fa836 commit 84f1d26

File tree

5 files changed

+33
-28
lines changed

5 files changed

+33
-28
lines changed

src/SUMMARY.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@
2323
- [SLOW (Protocol implementation)](./vision/projects/SLOW.md)
2424
- [😱 Status quo](./vision/status_quo.md)
2525
- [Template](./vision/status_quo/template.md)
26-
- [Alan runs into stack trouble](./vision/status_quo/alan_runs_into_stack_trouble.md)
26+
- [Alan finds dropping database handles is hard](./vision/status_quo/alan_finds_database_drops_hard.md)
2727
- [Alan hates writing a `Stream`](./vision/status_quo/alan_hates_writing_a_stream.md)
28+
- [Alan runs into stack trouble](./vision/status_quo/alan_runs_into_stack_trouble.md)
2829
- [Alan started trusting the Rust compiler, but then... async](./vision/status_quo/alan_started_trusting_the_rust_compiler_but_then_async.md)
30+
- [Barbara carefully dismisses embedded `Future`](./vision/status_quo/barbara_carefully_dismisses_embedded_future.md)
2931
- [Barbara makes their first foray into async](./vision/status_quo/barbara_makes_their_first_steps_into_async.md)
32+
- [Barbara plays with async](./vision/status_quo/barbara_plays_with_async.md)
33+
- [Barbara tries async streams](./vision/status_quo/barbara_tries_async_streams.md)
34+
- [Barbara trims a stacktrace](./vision/status_quo/barbara_trims_a_stacktrace.md)
3035
- [Grace deploys her service and hits obstacles](./vision/status_quo/grace_deploys_her_service.md)
3136
- [Niklaus wants to share knowledge](./vision/status_quo/niklaus_wants_to_share_knowledge.md)
3237
- [✨ Shiny future](./vision/shiny_future.md)

src/vision/status_quo/alan_finds_database_drops_hard.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ If you would like to expand on this story, or adjust the answers to the FAQ, fee
1111

1212
Alan has been adding an extension to YouBuy that launches a singleton actor which interacts with a Sqlite database using the `sqlx` crate. The Sqlite database only permits a single active connection at a time, but this is not a problem, because the actor is a singleton, and so there only should be one at a time. He consults the documentation for `sqlx` and comes up with the following code to create a connection and do the query he needs:
1313

14-
```rust
14+
```rust,ignore
1515
use sqlx::Connection;
1616
1717
#[async_std::main]
@@ -41,7 +41,7 @@ Alan tries to figure out what happened from the logs, but the only information h
4141

4242
He's a bit confused, because he's accustomed to having things generally be cleaned up automatically when they get dropped (for example, dropping a [`File`](https://doc.rust-lang.org/std/fs/struct.File.html) will close it). Searching the docs, he sees the [`close`](https://docs.rs/sqlx/0.5.1/sqlx/trait.Connection.html#tymethod.close) method, but the comments confirm that he shouldn't have to call it explicitly: "This method is not required for safe and consistent operation. However, it is recommended to call it instead of letting a connection drop as the database backend will be faster at cleaning up resources." Still, just in case, he decides to add a call to `close` into his code. It does seem to help some, but he is still able to reproduce the problem if he refreshes often enough. Feeling confused, he adds a log statement right before calling `close` to see if it is working:
4343

44-
```rust
44+
```rust,ignore
4545
use sqlx::Connection;
4646
4747
#[async_std::main]

src/vision/status_quo/barbara_carefully_dismisses_embedded_future.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ kernel does not expose a Future-based interface, so Barbara has to implement
3636
`Future` by hand rather than using async/await syntax. She starts with a
3737
skeleton:
3838

39-
```rust
39+
```rust,ignore
4040
/// Passes `buffer` to the kernel, and prints it to the console. Returns a
4141
/// future that returns `buffer` when the print is complete. The caller must
4242
/// call kernel_ready_for_callbacks() when it is ready for the future to return.
@@ -61,7 +61,7 @@ Note: All error handling is omitted to keep things understandable.
6161

6262
Barbara begins to implement `print_buffer`:
6363

64-
```rust
64+
```rust,ignore
6565
fn print_buffer(buffer: &'static mut [u8]) -> PrintFuture {
6666
kernel_set_print_callback(callback);
6767
kernel_start_print(buffer);
@@ -76,7 +76,7 @@ extern fn callback() {
7676

7777
So far so good. Barbara then works on `poll`:
7878

79-
```rust
79+
```rust,ignore
8080
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
8181
if kernel_is_print_done() {
8282
return Poll::Ready(kernel_get_buffer_back());
@@ -92,7 +92,7 @@ somewhere! Barbara puts the `Waker` in a global variable so the callback can
9292
find it (this is fine because the app is single threaded and callbacks do NOT
9393
interrupt execution the way Unix signals do):
9494

95-
```rust
95+
```rust,ignore
9696
static mut PRINT_WAKER: Option<Waker> = None;
9797
9898
extern fn callback() {
@@ -104,7 +104,7 @@ extern fn callback() {
104104

105105
She then modifies `poll` to set `PRINT_WAKER`:
106106

107-
```rust
107+
```rust,ignore
108108
fn poll(self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
109109
if kernel_is_print_done() {
110110
return Poll::Ready(kernel_get_buffer_back());

src/vision/status_quo/barbara_plays_with_async.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ that will wait for a certain duration to elapse before resolving.
4343
Borrowing again from the "Hello Tokio" tutorial to make sure she has the correct
4444
spelling for the tokio macros, she writes up the following code:
4545

46-
```rust
46+
```rust,ignore
4747
#[tokio::main]
4848
pub async fn main() {
4949
let mut rng = thread_rng();
@@ -72,7 +72,7 @@ seconds doing nothing, and giving no hints about what it's actually doing.
7272
So for the next iteration, Barbara wants to have a message printed out
7373
when each future is resolved. She tries this code at first:
7474

75-
```rust
75+
```rust,ignore
7676
let mut futures = Vec::new();
7777
for _ in 0..10 {
7878
let delay = rng.sample(t);
@@ -85,7 +85,7 @@ println!("Created 10 futures");
8585

8686
But the compiler gives this error:
8787

88-
```
88+
```ignore
8989
error[E0277]: `()` is not a future
9090
--> src\main.rs:13:71
9191
|
@@ -105,7 +105,7 @@ which looks interesting.
105105
Indeed, this struct is a future that will resolve instantly, which is what
106106
she wants:
107107

108-
```rust
108+
```rust,ignore
109109
for _ in 0..10 {
110110
let delay = rng.sample(t);
111111
futures.push(tokio::time::sleep(Duration::from_millis(delay)).then(|_| {
@@ -129,7 +129,7 @@ always printed all at once.
129129
Barbara has experience writing async code in JavaScript, and so she thinks for
130130
a moment about how this toy code might have looked like if she was using JS:
131131

132-
```javascript
132+
```javascript,ignore
133133
async function main() {
134134
const futures = [];
135135
for (let idx = 0; idx < 10; idx++) {
@@ -161,7 +161,7 @@ and remembers that there's a 3rd-party crate called "[futures][futures crate]"
161161
on crates.io that she's seen mentioned in some /r/rust posts. She checks the
162162
docs and finds the `join_all` function which looks like what she wants:
163163

164-
```rust
164+
```rust,ignore
165165
let mut futures = Vec::new();
166166
for _ in 0..10 {
167167
let delay = rng.sample(t);
@@ -182,7 +182,7 @@ rust futures are lazy, and won't make progress unless you await them.
182182
Happy with this success, Barbara continues to expand her toy program by making
183183
a few small adjustments:
184184

185-
```rust
185+
```rust,ignore
186186
for counter in 0..10 {
187187
let delay = rng.sample(t);
188188
let delay_future = tokio::time::sleep(Duration::from_millis(delay));
@@ -203,7 +203,7 @@ for counter in 0..10 {
203203

204204
This fails to compile:
205205

206-
```
206+
```ignore
207207
error[E0308]: mismatched types
208208
209209
= note: expected closure `[closure@src\main.rs:16:44: 19:14]`
@@ -220,7 +220,7 @@ entire future.
220220

221221
She first adds explicit type annotations to the Vec:
222222

223-
```rust
223+
```rust,ignore
224224
let mut futures: Vec<Box<dyn Future<Output=()>>> = Vec::new();
225225
```
226226

@@ -232,7 +232,7 @@ rust-analyzer perfectly handled this case.
232232
Now each future is boxed up, but there is one final error still,
233233
this time on the call to `join_all(futures).await`:
234234

235-
```
235+
```ignore
236236
error[E0277]: `dyn futures::Future<Output = ()>` cannot be unpinned
237237
--> src\main.rs:34:31
238238
|
@@ -245,7 +245,7 @@ intuition about what this API is for. But she is accustomed to just trying
245245
things in rust to see if they work. And indeed, after changing `Box::new` to
246246
`Box::pin`:
247247

248-
```rust
248+
```rust,ignore
249249
futures.push(Box::pin(delay_future.then(|_| {
250250
println!("Done!");
251251
std::future::ready(())
@@ -254,7 +254,7 @@ futures.push(Box::pin(delay_future.then(|_| {
254254

255255
and adjusting the type of the Vec:
256256

257-
```rust
257+
```rust,ignore
258258
let mut futures: Vec<Pin<Box<dyn Future<Output=()>>>> = Vec::new();
259259
```
260260

@@ -272,7 +272,7 @@ post about async rust a few weeks ago, and has a vague idea of how it looks.
272272

273273
She tries writing this:
274274

275-
```rust
275+
```rust,ignore
276276
futures.push(Box::pin(async || {
277277
tokio::time::sleep(Duration::from_millis(delay)).await;
278278
println!("Done after {}ms", delay);
@@ -281,7 +281,7 @@ futures.push(Box::pin(async || {
281281

282282
The compiler gives an error:
283283

284-
```
284+
```ignore
285285
error[E0658]: async closures are unstable
286286
--> src\main.rs:14:31
287287
|
@@ -296,7 +296,7 @@ error[E0658]: async closures are unstable
296296
Barbara knows that async is stable and using this nightly feature isn't what
297297
she wants. So the tries the suggestion made by the compiler and removes the `||` bars:
298298

299-
```rust
299+
```rust,ignore
300300
futures.push(Box::pin(async {
301301
tokio::time::sleep(Duration::from_millis(delay)).await;
302302
println!("Done after {}ms", delay);
@@ -305,7 +305,7 @@ futures.push(Box::pin(async {
305305

306306
A new error this time:
307307

308-
```
308+
```ignore
309309
error[E0597]: `delay` does not live long enough
310310
15 | | tokio::time::sleep(Duration::from_millis(delay)).await;
311311
| | ^^^^^ borrowed value does not live long enough
@@ -318,7 +318,7 @@ to an async block), but Barbara's experience with rust tells her that it's a ver
318318
consistent language. Maybe the same keyword used in move closures will work here?
319319
She tries it:
320320

321-
```rust
321+
```rust,ignore
322322
futures.push(Box::pin(async move {
323323
tokio::time::sleep(Duration::from_millis(delay)).await;
324324
println!("Done after {}ms", delay);

src/vision/status_quo/barbara_trims_a_stacktrace.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ If you would like to expand on this story, or adjust the answers to the FAQ, fee
1818

1919
Barbara is triaging the reported bugs for her SLOW library. For each bug, she tries to quickly see if she can diagnose the basic area of code that is affected so she knows which people to ping to help fix it. She opens a bug report from a user complaining about a panic when too many connections arrive at the same time. The bug report includes a backtrace from the user's code, and it looks like this:
2020

21-
```
21+
```ignore
2222
thread 'main' panicked at 'something bad happened here', src/main.rs:16:5
2323
stack backtrace:
2424
0: std::panicking::begin_panic
@@ -74,7 +74,7 @@ Barbara finds the text overwhelming. She can't just browse it to figure out what
7474

7575
She's a bit confused by the `::{closure}` lines on her symbols but she learned by now that this is normal for `async fn`. After some work, she has reduced her stack to this:
7676

77-
```
77+
```ignore
7878
thread 'main' panicked at 'something bad happened here', src/main.rs:16:5
7979
stack backtrace:
8080
1: slow_rs::process_one::{{closure}} at ./src/main.rs:16:5
@@ -117,7 +117,7 @@ Fin.
117117
<details>
118118
<summary>(click to see how a backtrace looks in lldb)</summary>
119119

120-
```
120+
```ignore
121121
* thread #1, name = 'foo', stop reason = breakpoint 1.1
122122
* frame #0: 0x0000555555583d24 foo`foo::main::_$u7b$$u7b$closure$u7d$$u7d$::_$u7b$$u7b$closure$u7d$$u7d$::h617d49d0841ffc0d((null)=closure-0 @ 0x00007fffffffae38, (null)=<unavailable>) at main.rs:11:13
123123
frame #1: 0x0000555555583d09 foo`_$LT$T$u20$as$u20$futures_util..fns..FnOnce1$LT$A$GT$$GT$::call_once::hc559b1f3f708a7b0(self=closure-0 @ 0x00007fffffffae68, arg=<unavailable>) at fns.rs:15:9

0 commit comments

Comments
 (0)