summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorxioren <40043405+xioren@users.noreply.github.com>2021-05-24 20:56:31 -0700
committerGitHub <noreply@github.com>2021-05-24 20:56:31 -0700
commit478f717377c4cd60cfce112b8b21d58031b118b4 (patch)
tree51807cec7302abe58bf5ccf8ad12e300688eea8c /lib
parentd217888e5679aff063668930bd00892c4f5cb2b3 (diff)
downloadNim-478f717377c4cd60cfce112b8b21d58031b118b4.tar.gz
Move async example to asynchronous version of proc (#18078)
* improve runnableExamples in std/httpclient

* Add synchronous example.

* Update lib/pure/httpclient.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/httpclient.nim21
1 files changed, 14 insertions, 7 deletions
diff --git a/lib/pure/httpclient.nim b/lib/pure/httpclient.nim
index 86708dc40..0dbf8a045 100644
--- a/lib/pure/httpclient.nim
+++ b/lib/pure/httpclient.nim
@@ -574,15 +574,11 @@ proc newHttpClient*(userAgent = defUserAgent, maxRedirects = 5,
   ##
   ## `headers` specifies the HTTP Headers.
   runnableExamples:
-    import std/[asyncdispatch, httpclient, strutils]
+    import std/strutils
 
-    proc asyncProc(): Future[string] {.async.} =
-      var client = newAsyncHttpClient()
-      return await client.getContent("http://example.com")
-
-    let exampleHtml = waitFor asyncProc()
+    let exampleHtml = newHttpClient().getContent("http://example.com")
     assert "Example Domain" in exampleHtml
-    assert not ("Pizza" in exampleHtml)
+    assert "Pizza" notin exampleHtml
 
   new result
   result.headers = headers
@@ -616,6 +612,17 @@ proc newAsyncHttpClient*(userAgent = defUserAgent, maxRedirects = 5,
   ## connections.
   ##
   ## `headers` specifies the HTTP Headers.
+  runnableExamples:
+    import std/[asyncdispatch, strutils]
+
+    proc asyncProc(): Future[string] {.async.} =
+      let client = newAsyncHttpClient()
+      result = await client.getContent("http://example.com")
+
+    let exampleHtml = waitFor asyncProc()
+    assert "Example Domain" in exampleHtml
+    assert "Pizza" notin exampleHtml
+  
   new result
   result.headers = headers
   result.userAgent = userAgent