various small documentation improvements (#18602)

This commit is contained in:
Miran 2021-07-28 14:31:13 +02:00 • committed by GitHub
commit e616675c41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 123 additions and 97 deletions

View file

@ -42,12 +42,12 @@
##
## Code to read some data from a socket may look something like this:
##
## .. code-block:: Nim
## var future = socket.recv(100)
## future.addCallback(
## proc () =
## echo(future.read)
## )
## .. code-block:: Nim
## var future = socket.recv(100)
## future.addCallback(
## proc () =
## echo(future.read)
## )
##
## All asynchronous functions returning a `Future` will not block. They
## will not however return immediately. An asynchronous function will have
@ -104,20 +104,20 @@
## The most reliable way to handle exceptions is to use `yield` on a future
## then check the future's `failed` property. For example:
##
## .. code-block:: Nim
## var future = sock.recv(100)
## yield future
## if future.failed:
## # Handle exception
## .. code-block:: Nim
## var future = sock.recv(100)
## yield future
## if future.failed:
## # Handle exception
##
## The `async` procedures also offer limited support for the try statement.
##
## .. code-block:: Nim
## try:
## let data = await sock.recv(100)
## echo("Received ", data)
## except:
## # Handle exception
## .. code-block:: Nim
## try:
## let data = await sock.recv(100)
## echo("Received ", data)
## except:
## # Handle exception
##
## Unfortunately the semantics of the try statement may not always be correct,
## and occasionally the compilation may fail altogether.