Skip to content

Commit b5ecce7

Browse files
committed
Update docs
* new mdbook version with built-in Nim highlighting support * describe examples in a dedicated page * fixes
1 parent 28a100b commit b5ecce7

File tree

6 files changed

+57
-67
lines changed

6 files changed

+57
-67
lines changed

.github/workflows/doc.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
with:
2323
crate: mdbook
2424
use-tool-cache: true
25-
version: "0.4.35"
25+
version: "0.4.36"
2626
- uses: actions-rs/[email protected]
2727
with:
2828
crate: mdbook-toc
@@ -37,7 +37,7 @@ jobs:
3737
with:
3838
crate: mdbook-admonish
3939
use-tool-cache: true
40-
version: "1.13.1"
40+
version: "1.14.0"
4141

4242
- uses: jiro4989/setup-nim-action@v1
4343
with:

docs/src/SUMMARY.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
- [Introduction](./introduction.md)
2-
- [Getting started](./getting_started.md)
2+
- [Examples](./examples.md)
33

44
# User guide
55

@@ -8,3 +8,7 @@
88
- [Errors and exceptions](./error_handling.md)
99
- [Tips, tricks and best practices](./tips.md)
1010
- [Porting code to `chronos`](./porting.md)
11+
12+
# Developer guide
13+
14+
- [Updating this book](./book.md)

docs/src/async_procs.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
Async procedures are those that interact with `chronos` to cooperatively
44
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.
77

88
Async procedures are marked with the `{.async.}` pragma and return a `Future`
99
indicating the state of the operation.
@@ -25,6 +25,9 @@ echo p().type # prints "Future[system.void]"
2525

2626
## `await` keyword
2727

28+
The `await` keyword operates on `Future` instances typically returned from an
29+
`async` procedure.
30+
2831
Whenever `await` is encountered inside an async procedure, control is given
2932
back to the dispatcher for as many steps as it's necessary for the awaited
3033
future to complete, fail or be cancelled. `await` calls the
@@ -53,13 +56,13 @@ waitFor p3()
5356

5457
```admonition warning
5558
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.
5760
5861
In particular, if two `async` procedures have access to the same mutable state,
5962
the value before and after `await` might not be the same as the order of execution is not guaranteed!
6063
```
6164

62-
## Raw procedures
65+
## Raw async procedures
6366

6467
Raw async procedures are those that interact with `chronos` via the `Future`
6568
type but whose body does not go through the async transformation.
@@ -83,7 +86,7 @@ proc rawFailure(): Future[void] {.async: (raw: true).} =
8386
fut
8487
```
8588

86-
Raw functions can also use checked exceptions:
89+
Raw procedures can also use checked exceptions:
8790

8891
```nim
8992
proc rawAsyncRaises(): Future[void] {.async: (raw: true, raises: [IOError]).} =

docs/src/examples.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Examples
2+
3+
Examples are available in the [`docs/examples/`](https://github.com/status-im/nim-chronos/tree/master/docs/examples/) folder.
4+
5+
## Basic concepts
6+
7+
* [cancellation](https://github.com/status-im/nim-chronos/tree/master/docs/examples/cancellation.nim) - Cancellation primer
8+
* [timeoutsimple](https://github.com/status-im/nim-chronos/tree/master/docs/examples/timeoutsimple.nim) - Simple timeouts
9+
* [timeoutcomposed](https://github.com/status-im/nim-chronos/tree/master/docs/examples/examples/timeoutcomposed.nim) - Shared timeout of multiple tasks
10+
11+
## TCP
12+
13+
* [tcpserver](https://github.com/status-im/nim-chronos/tree/master/docs/examples/tcpserver.nim) - Simple TCP/IP v4/v6 echo server
14+
15+
## HTTP
16+
17+
* [httpget](https://github.com/status-im/nim-chronos/tree/master/docs/examples/httpget.nim) - Downloading a web page using the http client
18+
* [twogets](https://github.com/status-im/nim-chronos/tree/master/docs/examples/twogets.nim) - Download two pages concurrently

docs/src/introduction.md

+24-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,34 @@ transformation features provided by Nim.
77
Features include:
88

99
* Asynchronous socket and process I/O
10-
* HTTP server with SSL/TLS support out of the box (no OpenSSL needed)
10+
* HTTP client / server with SSL/TLS support out of the box (no OpenSSL needed)
1111
* Synchronization primitivies like queues, events and locks
12-
* Cancellation
12+
* [Cancellation](./concepts.md#cancellation)
1313
* Efficient dispatch pipeline with excellent multi-platform support
1414
* Exception [effect support](./guide.md#error-handling)
1515

16+
## Installation
17+
18+
Install `chronos` using `nimble`:
19+
20+
```text
21+
nimble install chronos
22+
```
23+
24+
or add a dependency to your `.nimble` file:
25+
26+
```text
27+
requires "chronos"
28+
```
29+
30+
and start using it:
31+
32+
```nim
33+
{{#include ../examples/httpget.nim}}
34+
```
35+
36+
There are more [examples](./examples.md) throughout the manual!
37+
1638
## Platform support
1739

1840
Several platforms are supported, with different backend [options](./concepts.md#compile-time-configuration):
@@ -22,10 +44,6 @@ Several platforms are supported, with different backend [options](./concepts.md#
2244
* OSX / BSD: [`kqueue`](https://en.wikipedia.org/wiki/Kqueue) / `poll`
2345
* Android / Emscripten / posix: `poll`
2446

25-
## Examples
26-
27-
Examples are available in the [`docs/examples/`](https://github.com/status-im/nim-chronos/docs/examples) folder.
28-
2947
## API documentation
3048

3149
This guide covers basic usage of chronos - for details, see the

0 commit comments

Comments
 (0)