From 42a64245f81c1975845f1f4e8018f97ef350c153 Mon Sep 17 00:00:00 2001 From: Tristram Oaten Date: Mon, 20 Apr 2020 17:44:25 +0100 Subject: [PATCH] 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) --- lib/pure/httpclient.nim | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim index 5c53c1a396b96..5d44fce7aaaa6 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