2
2
3
3
Async procedures are those that interact with ` chronos ` to cooperatively
4
4
suspend and resume their execution depending on the completion of other
5
- async procedures which themselves may be waiting for I/O to complete, timers to
6
- expire or tasks running on other threads to complete .
5
+ async procedures, timers, tasks on other threads or asynchronous I/O scheduled
6
+ with the operating system .
7
7
8
8
Async procedures are marked with the ` {.async.} ` pragma and return a ` Future `
9
9
indicating the state of the operation.
@@ -25,6 +25,9 @@ echo p().type # prints "Future[system.void]"
25
25
26
26
## ` await ` keyword
27
27
28
+ The ` await ` keyword operates on ` Future ` instances typically returned from an
29
+ ` async ` procedure.
30
+
28
31
Whenever ` await ` is encountered inside an async procedure, control is given
29
32
back to the dispatcher for as many steps as it's necessary for the awaited
30
33
future to complete, fail or be cancelled. ` await ` calls the
@@ -53,13 +56,13 @@ waitFor p3()
53
56
54
57
``` admonition warning
55
58
Because `async` procedures are executed concurrently, they are subject to many
56
- of the same risks that typically accompany multithreaded programming
59
+ of the same risks that typically accompany multithreaded programming.
57
60
58
61
In particular, if two `async` procedures have access to the same mutable state,
59
62
the value before and after `await` might not be the same as the order of execution is not guaranteed!
60
63
```
61
64
62
- ## Raw procedures
65
+ ## Raw async procedures
63
66
64
67
Raw async procedures are those that interact with ` chronos ` via the ` Future `
65
68
type but whose body does not go through the async transformation.
@@ -83,7 +86,7 @@ proc rawFailure(): Future[void] {.async: (raw: true).} =
83
86
fut
84
87
```
85
88
86
- Raw functions can also use checked exceptions:
89
+ Raw procedures can also use checked exceptions:
87
90
88
91
``` nim
89
92
proc rawAsyncRaises(): Future[void] {.async: (raw: true, raises: [IOError]).} =
0 commit comments