From 472f152eaec3d93a2ec0e73751eadead477f54d7 Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Fri, 26 Jul 2024 08:12:41 -0600 Subject: [PATCH] Ch. 17: fix diagrams and embed them in the text - Swap the ordering to match the order in the text (concurrent is first, at least for now). - Make them go left-to-right instead of top-to-bottom for compactness in the text. - Fix rendering issues resulting from the VS Code extension doing things that normal `dot` does not, for who knows what reasons. --- dot/trpl17-01.dot | 45 +++++++++++---- dot/trpl17-02.dot | 40 +++----------- src/ch17-00-async-await.md | 16 ++++++ src/img/trp17-02.svg | 1 + src/img/trpl17-01.svg | 110 +++++++++++++++++++++++++++++++++++++ src/img/trpl17-02.svg | 94 +++++++++++++++++++++++++++++++ 6 files changed, 262 insertions(+), 44 deletions(-) create mode 100644 src/img/trp17-02.svg create mode 100644 src/img/trpl17-01.svg create mode 100644 src/img/trpl17-02.svg diff --git a/dot/trpl17-01.dot b/dot/trpl17-01.dot index d90c85b8ee..97bd15e894 100644 --- a/dot/trpl17-01.dot +++ b/dot/trpl17-01.dot @@ -1,21 +1,44 @@ digraph { dpi = 300.0; - Parallel [label = "Parallel";shape = "plaintext";]; - rankdir = "TB"; - splines = false; - cluster = true; + rankdir = "LR"; + + // makes ordering between subgraphs work + newrank = true; node [shape = diamond;]; - subgraph cluster_ColleagueA { - newrank = true; - label = "Task 1"; - A1 -> A2 -> A3 -> A4; + subgraph cluster_task_a { + label = "Task A"; + + A1; + A2; + A3; + A4; + + A1 -> A2 -> A3 -> A4 -> A0 [style = invis;]; + + // for vertical alignment purposes only + A0 [style = invis;]; + + // Makes the heights line up between the boxes. + A4 -> A0 [style = invis;]; } - subgraph cluster_ColleagueB { - label = "Task 2"; - B1 -> B2 -> B3; + subgraph cluster_task_b { + label = "Task B"; + + // for horizontal alignment purposes only + // newrank = true; + + B0 [style = invis;]; + + B1; + B2; + B3; + + B0 -> B1 -> B2 -> B3 [style = invis;]; } + + A1 -> B1 -> A2 -> B2 -> A3 -> A4 -> B3; } \ No newline at end of file diff --git a/dot/trpl17-02.dot b/dot/trpl17-02.dot index 3c8d2a18a3..512f33cb9b 100644 --- a/dot/trpl17-02.dot +++ b/dot/trpl17-02.dot @@ -1,46 +1,20 @@ digraph { dpi = 300.0; - Concurrent [label = "Concurrent";shape = "plaintext";]; - rankdir = "TB"; + rankdir = "LR"; splines = false; cluster = true; node [shape = diamond;]; - subgraph cluster_task_a { - label = "Task A"; - - // makes ordering between subgraphs work + subgraph cluster_ColleagueA { newrank = true; - - A1; - A2; - A3; - A4; - - // for vertical alignment purposes only - A0 [style = invis;]; - - edge [style = invis;]; + label = "Task 1"; + A1 -> A2 -> A3 -> A4; } - subgraph cluster_task_b { - label = "Task B"; - cluster = true; - - // for vertical alignment purposes only - newrank = true; - - B0 [style = invis;]; - - B1; - B2; - B3; + subgraph cluster_ColleagueB { + label = "Task 2"; + B1 -> B2 -> B3; } - - A1 -> B1 -> A2 -> B2 -> A3 -> A4 -> B3; - - // Makes the heights line up between the boxes. - A4 -> A0 [style = invis;]; } \ No newline at end of file diff --git a/src/ch17-00-async-await.md b/src/ch17-00-async-await.md index 22f200fa49..e68c7420fc 100644 --- a/src/ch17-00-async-await.md +++ b/src/ch17-00-async-await.md @@ -81,10 +81,26 @@ to the other. You are just one person, and you cannot make progress on both tasks at the exact same time—but you can multi-task, making progress on multiple tasks by switching between them. +
+ +Concurrent work flow + +
Figure 17-1: A concurrent workflow, switching between Task A and Task B
+ +
+ When you agree to split up a group of tasks between the people on the team, with each person taking one task and working on it alone, this is *parallelism*. Each person on the team can make progress at the exact same time. +
+ +Concurrent work flow + +
Figure 17-2: A parallel workflow, where work happens on Task A and Task B independently
+ +
+ With both of these situations, you might have to coordinate between different tasks. Maybe you *thought* the task that one person was working on was totally independent from everyone else’s work, but it actually needs something finished diff --git a/src/img/trp17-02.svg b/src/img/trp17-02.svg new file mode 100644 index 0000000000..1ad970d72c --- /dev/null +++ b/src/img/trp17-02.svg @@ -0,0 +1 @@ +Task 1Task 2ParallelA1A2A3A4B1B2B3 \ No newline at end of file diff --git a/src/img/trpl17-01.svg b/src/img/trpl17-01.svg new file mode 100644 index 0000000000..c99989ec31 --- /dev/null +++ b/src/img/trpl17-01.svg @@ -0,0 +1,110 @@ + + + + + + + + +cluster_task_a + +Task A + + +cluster_task_b + +Task B + + + +A1 + +A1 + + + +A2 + +A2 + + + + +B1 + +B1 + + + +A1->B1 + + + + + +A3 + +A3 + + + + +B2 + +B2 + + + +A2->B2 + + + + + +A4 + +A4 + + + + +A3->A4 + + + + + + + + +B3 + +B3 + + + +A4->B3 + + + + + + + +B1->A2 + + + + + + +B2->A3 + + + + + + diff --git a/src/img/trpl17-02.svg b/src/img/trpl17-02.svg new file mode 100644 index 0000000000..1ddb5d4cad --- /dev/null +++ b/src/img/trpl17-02.svg @@ -0,0 +1,94 @@ + + + + + + + + +cluster_ColleagueA + +Task 1 + + +cluster_ColleagueB + +Task 2 + + + +A1 + +A1 + + + +A2 + +A2 + + + +A1->A2 + + + + + +A3 + +A3 + + + +A2->A3 + + + + + +A4 + +A4 + + + +A3->A4 + + + + + +B1 + +B1 + + + +B2 + +B2 + + + +B1->B2 + + + + + +B3 + +B3 + + + +B2->B3 + + + + +