@@ -57,7 +57,7 @@ def combined: Future[Int] = async { // 02
5757val x : Int = Await .result(combined, 10 .seconds) // 05
5858```
5959
60- Lines 1 defines an asynchronous method: it returns a ` Future ` .
60+ Line 1 defines an asynchronous method: it returns a ` Future ` .
6161
6262Line 2 begins an ` async ` block. During compilation,
6363the contents of this block will be analyzed to identify
@@ -69,14 +69,14 @@ computation in the `async` block is not executed
6969on the caller's thread.
7070
7171Line 3 begins by triggering ` slowCalcFuture ` , and then
72- suspending until it has been calculating . Only after it
72+ suspending until it has been calculated . Only after it
7373has finished, we trigger it again, and suspend again.
7474Finally, we add the results and complete ` combined ` , which
7575in turn will release line 5 (unless it had already timed out).
7676
77- It is important to note that while line 1-4 is non-blocking,
78- it is not parallel. If we wanted to parallelize the two computations,
79- we could rearrange the code as follows.
77+ It is important to note that while lines 1-4 are non-blocking,
78+ they are not parallel. If we wanted to parallelize the two computations,
79+ we could rearrange the code as follows:
8080
8181``` scala
8282def combined : Future [Int ] = async {
@@ -102,8 +102,8 @@ def combined: Future[Int] = for {
102102```
103103
104104The ` async ` approach has two advantages over the use of
105- ` map ` and ` flatMap ` .
106- 1 . The code more directly reflects the programmers intent,
105+ ` map ` and ` flatMap ` :
106+ 1 . The code more directly reflects the programmer's intent,
107107 and does not require us to name the results ` r1 ` and ` r2 ` .
108108 This advantage is even more pronounced when we mix control
109109 structures in ` async ` blocks.
@@ -126,8 +126,8 @@ difficult to understand.
126126
127127## How it works
128128
129- - The async macro analyses the block of code, looking for control
130- structures and locations of await calls. It then breaks the code
129+ - The ` async ` macro analyses the block of code, looking for control
130+ structures and locations of ` await ` calls. It then breaks the code
131131 into 'chunks'. Each chunk contains a linear sequence of statements
132132 that concludes with a branching decision, or with the registration
133133 of a subsequent state handler as the continuation.
@@ -136,13 +136,13 @@ difficult to understand.
136136 "A Normal Form" (ANF), and roughly means that:
137137 - ` if ` and ` match ` constructs are only used as statements;
138138 they cannot be used as an expression.
139- - calls to await are not allowed in compound expressions.
139+ - calls to ` await ` are not allowed in compound expressions.
140140 - Identify vals, vars and defs that are accessed from multiple
141141 states. These will be lifted out to fields in the state machine
142142 object.
143143 - Synthesize a class that holds:
144- - an integer representing the current state ID
145- - the lifted definitions
144+ - an integer representing the current state ID.
145+ - the lifted definitions.
146146 - an ` apply(value: Try[Any]): Unit ` method that will be
147147 called on completion of each future. The behavior of
148148 this method is determined by the current state. It records
@@ -151,12 +151,12 @@ difficult to understand.
151151 - the ` resume(): Unit ` method that switches on the current state
152152 and runs the users code for one 'chunk', and either:
153153 a) registers the state machine as the handler for the next future
154- b) completes the result Promise of the async block, if at the terminal state.
154+ b) completes the result Promise of the ` async ` block, if at the terminal state.
155155 - an ` apply(): Unit ` method that starts the computation.
156156
157157## Limitations
158158 - See the [ neg] ( https://github.com/scala/async/tree/master/src/test/scala/scala/async/neg ) test cases
159- for constructs that are not allowed in a async block
159+ for constructs that are not allowed in an ` async ` block.
160160 - See the [ issue list] ( https://github.com/scala/async/issues?state=open ) for which of these restrictions are planned
161161 to be dropped in the future.
162162 - See [ #13 ] ( https://github.com/scala/async/issues/13 ) for why ` await ` is not possible in closures, and for suggestions on
0 commit comments