summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorTristram Oaten <tristram@oaten.name>2020-04-20 17:44:25 +0100
committerDominik Picheta <dominikpicheta@googlemail.com>2020-04-21 00:00:30 +0100
commit42a64245f81c1975845f1f4e8018f97ef350c153 (patch)
tree35e479b957473da8fdbc5c620d7885674fbcb5b8 /lib
parent67d71bb76d4c3d78302a452623d4507c783c6cc9 (diff)
downloadNim-42a64245f81c1975845f1f4e8018f97ef350c153.tar.gz
Fix broken async httpclient example
As the async httpclient is almost certainly the first async example beginners will want to try, we OWE it to them to give them a real example.

Example repeated here for clarity:

```nim
import asyncdispatch, httpclient

proc asyncProc(): Future[string] {.async.} =
  var client = newAsyncHttpClient()
  return await client.getContent("http://example.com")

echo waitFor asyncProc()
```

This is my first Nim contribution, please let me know if the code is right. (it runs on my machine, but may not be the best example)
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/httpclient.nim10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim
index 5c53c1a39..5d44fce7a 100644
--- a/lib/pure/httpclient.nim
+++ b/lib/pure/httpclient.nim
@@ -25,15 +25,19 @@
 ## ``AsyncHttpClient``:
 ##
 ## .. code-block:: Nim
-##   import httpClient
+## import asyncdispatch, httpclient
+## 
+## proc asyncProc(): Future[string] {.async.} =
 ##   var client = newAsyncHttpClient()
-##   echo await client.getContent("http://google.com")
+##   return await client.getContent("http://example.com")
+## 
+## echo waitFor asyncProc()
 ##
 ## The functionality implemented by ``HttpClient`` and ``AsyncHttpClient``
 ## is the same, so you can use whichever one suits you best in the examples
 ## shown here.
 ##
-## **Note:** You will need to run asynchronous examples in an async proc
+## **Note:** You need to run asynchronous examples in an async proc
 ## otherwise you will get an ``Undeclared identifier: 'await'`` error.
 ##
 ## Using HTTP POST